Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move tui to a (default) subcommand #270

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open

Conversation

mixmix
Copy link
Contributor

@mixmix mixmix commented Oct 30, 2024

Problem

I was hitting some problems with options colliding between the root entropy command and the other sub-commands like entropy account register.

Solution

Reading the commander docs I saw there was an option for commands { default: true }. This allows us to move tui functionality into a sub-command entropy tui AND sets this as the default command that is run (if no sub-command is called).

This resolves almost all the problems in #265 and means that we can have

  • the same env for TUI and CLI
  • no collision between the root command and subcommand options!

@mixmix mixmix mentioned this pull request Oct 30, 2024
8 tasks
@mixmix
Copy link
Contributor Author

mixmix commented Oct 30, 2024

In testing this, I discovered that entropy --help was outputting help for all the commands (good) but that there was no mention of --version. I've added a commit which gives you output about the two major use paths:

$ entropy --help

Usage: entropy [options]

TUI (text user interface) for interacting with entropy.xyz. A good place to start.

Options:
  -v, --version                 Displays the current running version of Entropy CLI
  -cv, --core-version           Displays the current running version of the Entropy Protocol
  -a, --account <name|address>  Sets the account for the session. Defaults to the last set account (or the first account if one has not been set before). (default: "mix", env: ENTROPY_ACCOUNT)
  -e, --endpoint <url>          Runs entropy with the given endpoint and ignores network endpoints in config. Can also be given a stored endpoint name from config eg: `entropy --endpoint test-net`. (default: "wss://testnet.entropy.xyz/", env:
                                ENTROPY_ENDPOINT)
  -h, --help                    display help for command


---

Usage: entropy [options] [command]

CLI interface for interacting with entropy.xyz.

Options:
  -h, --help                                 display help for command

Commands:
  balance [options] <account>                Command to retrieive the balance of an account on the Entropy Network
  account                                    Commands to work with accounts on the Entropy Network
  transfer [options] <destination> <amount>  Transfer funds between two Entropy accounts.
  sign [options] <msg>                       Sign a message using the Entropy network. Output is a JSON { verifyingKey, signature }
  program                                    Commands for working with programs deployed to the Entropy Network
  tui [options]                              TUI (text user interface) for interacting with entropy.xyz. A good place to start.
  help [command]                             display help for command

@mixmix
Copy link
Contributor Author

mixmix commented Oct 30, 2024

I think I want to discuss this as a team.

Requirements

Any good solution will satisfy

  1. entropy --help is clear
    • shows tui options (if entropy [options] is the tui command)
    • shows commands
  2. entropy -v and entropy [command] -vk <string> coexist
  3. --endpoint works for CLI + TUI
    • e.g. entropy -e ws://testnet.entropy.xyz and entropy [command] -e -e ws://testnet.entropy.xyz` coexist

Option A - split out entropy-tui

  • ✔️ (1)
  • ❌ (2) fail - -v and -vk collide
  • ✔️ (3)

We can mention there is a tui option in the entropy --help

Option B - tui as default sub-command

This is what this PR is doing.

  • 😢 (1) semi-fails
    • the help docs on root are a bit messy
    • I got into the source code of commander to hack the help output ... it's possible to do betterbut it gets ugly fast.
  • ✔️ (2) succeeds
  • ✔️ (3) succeeds

Option C - tui as root command

This is how dev currently is. It sucks because we have to use ENTROPY_TUI_ENDPOINT which we have already seen needlessly trip up Peg.

  • ✔️ (1) yes
  • ❌ (2) fail - -v and -vk collide
  • ❌ (3) fail - we have different ENV and flags for TUI + CLI endpoint config

For (3) We could get very fancy and check program.opts versus command.opts and make sure the opts get through to the right level of action .. and not-overridden by a default.... there's a positional opts config we could mess with but then that makes the signatures VERY rigid.

Option D - entropy tui

  • ✔️ (1)
  • ❌ (2) still have to navigate -v vs -vk
  • ✔️ (3)

similar to (B), except entropy alone now does nothing.
We can recommend that a user runs entropy tui if they are new

@mixmix
Copy link
Contributor Author

mixmix commented Oct 30, 2024

Option E - no flag collisions

Replace -vk with e.g. -k
Probably replace -pmk with -p

The whole short-code is designed to be a single letter. We're hitting -v vs -vk tension exactly because of how short-codes work (-vk = -v + -k)

I strongly believe we should NOT change -v, --version

@mixmix
Copy link
Contributor Author

mixmix commented Oct 31, 2024

Ok! where this has settled

1. entropy now just prints help

Usage: entropy [options] [command]

CLI interface for interacting with entropy.xyz.

Options:
  -v, --version                              Displays the current running version of Entropy CLI
  -cv, --core-version                        Displays the current running version of the Entropy Protocol
  -h, --help                                 display help for command

Commands:
  tui [options]                              Text-based User Interface (interactive)
  account                                    Commands to work with accounts on the Entropy Network
  sign [options] <msg>                       Sign a message using the Entropy network. Output is a JSON {
                                             verifyingKey, signature }
  balance [options] <account>                Command to retrieive the balance of an account on the Entropy
                                             Network
  transfer [options] <destination> <amount>  Transfer funds between two Entropy accounts.
  program                                    Commands for working with programs deployed to the Entropy
                                             Network

2. entropy tui launches the tui

3. entropy tui --help gives help only for the tui

Usage: entropy tui [options]

Text-based User Interface (interactive)

Options:
  -a, --account <name|address>  Sets the account for the session. Defaults to the last set account (or the
                                first account if one has not been set before). (default: "mix", env:
                                ENTROPY_ACCOUNT)
  -e, --endpoint <url>          Runs entropy with the given endpoint and ignores network endpoints in config.
                                Can also be given a stored endpoint name from config eg: `entropy --endpoint
                                test-net`. (default: "wss://testnet.entropy.xyz/", env: ENTROPY_ENDPOINT)
  -h, --help                    display help for command

4. There are now no collisions between a "root command" and "sub-command" on:

  • endpoint (-e and ENTROPY_ENDPOINT work same for TUI/ CLI)
  • account (this was broken for tui!)

launchTui(entropy, opts)

// print entropy help and exit
cli.help()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is displaying the help text when a user types only entropy what we expect to happen? Also should we update the package json script for yarn start to start the TUI instead of just displaying the help text?

Comment on lines +78 to +87
async function setupConfig () {
let storedConfig = await config.get()

// set selectedAccount if we can
if (!storedConfig.selectedAccount && storedConfig.accounts.length) {
storedConfig = await config.setSelectedAccount(storedConfig.accounts[0])
}

return storedConfig
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a thought: do we need to implement this for the CLI too? or are we assuming that a user will have an account selected when using the programmatic cli?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants