-
Notifications
You must be signed in to change notification settings - Fork 356
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
Replace positional arguments with flags in CLI #2275
Replace positional arguments with flags in CLI #2275
Conversation
Just a note not to forget to update the % gm hermes cc
"./hermes" create channel ibc0 ibc1 --port-a transfer --port-b transfer |
Yes, I will check all the commands which use hermes and update them with the new flags. |
Just some pointers to help add unit-tests for clap CLI arg parsing -> clap-rs/clap#1355 (comment) |
relayer-cli/src/commands/keys/add.rs
Outdated
fn test_keys_add_key_and_mnemonic() { | ||
assert!(KeysAddCmd::try_parse_from(&["test", "--chain", "chain_id", "--key-file", "key_file", "--mnemonic-file", "mnemonic_file"]).is_err()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @hu55a1n1 @mzabaluev do these examples for unit-testing the clap arg parsing seem good to you ? Or do you have any feedback regarding unit-testing the clap arg parsing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Given how many changes are/ will be in this PR already, can we do the clap tests in a different PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is exactly what I had in mind! 👌 Would be nice to get this in before relayer-cli v1. I agree it's better to do it in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping there is some framework to provide some handy test macros, but I can't find any at the moment.
This will do, we can add more cases to exercise.
If you have time, consider creating some helper macros like:
assert_valid_cmdline!("--chain", "chain_id", "--key-file", "key_file", "--mnemonic-file", "mnemonic_file");
assert_invalid_cmdline!("--chain", "chain_id", "--key-file", "key_file", "--mnemonic-file", "mnemonic_file");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for all the feedback! I will check this as soon as this PR is merged and I work on the unit-tests.
I have found trycmd, which looks like a useful tool to organize CLI tests in a self-documented way. This could also augment our manually maintained command examples in the guide mdbook. Not in scope for this PR, though. |
Great stuff! Just one question: what's the rationale behind using |
Since we use only long flags, the idea was to reduce the flag length for cases which are still meaningful after being shortened. This was done for the flags |
Is there an easy way to allow both |
Yes, with clap's
Then both these tests will pass:
|
Sweet, then let's do this. Remains to decide whether we want the long ( |
I have a preference for the shortened version, but I think my opinion is biased due to using them when replacing and testing the commands. |
I would also agree with sticking with the long versions, if only to be more explicit. I think this applies to |
I would rather add the aliases to this PR to keep PR churn down, if that's okay. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work!
I've reviewed "my turf"...
health-check
,help
These were easy: no parameters, nothing to change!
So I took it upon myself to look at some more commands.
Please also merge with recent master as there are some new conflicts. |
What's the reasoning behind having |
The choice of prefixing |
…'s help for autogenerated arguments (eg. --help)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @ljoss17, thank you so much! Many thanks to all reviewers as well :)
* Updated CLI commands to take flags everywhere and updated e2e tests accordingly * Updated gm to use flags when calling Hermes * Added missing flags to e2e test for 'query client state' command * Fixed flag errors in e2e tests and removed conflicting short flag. * Removed all short flags and updated CLI commands comments * Removed forgotten short flags. * Updated Hermes guide with flags instead of positional arguments * Updated script and comment with new long flags for Hermes * Completed 'tx raw upgrade-' commands guide page. Updated Testing client upgrade guide page * Added changelog entry * Added example unit-tests to the 'keys add' command * Added value names to parameters and removed cli parsing unit-tests * Cargo fmt changes * Updated flags in order to reflect ADR 010 * Updated guide to reflect flag changes from ADR 010 * Updated gm script and e2e tests to match flag changes from ADR 010 * Fixed ADR 010 typo * Remove short flags from `key` error messages * Fix inconsistent error messaging in channel.rs * Fix more inconsistent error messaging * Run cargo fmt * Fix commands that use deprecated `-c` flag * Added the query transfer subcommand in docs. * Scrub query clients * Scrub query client state * Removed excessive debug line * Disabled filtering for query channels CLI * Added aliases for 'connection', 'channel' and 'sequence' flags * Fixed error in CLI replacing HeightQuery with QueryHeight * Fix cargo fmt * Changed 'version' to 'channel-version' for 'hermes create channel' command * Separated 'hermes create channel' help into short and long message * Updated 'hermes listen' so that '--events' flag can take multiple values * Updated guide with new '--events' flag for 'hermes listen' * Start all arguments help text with an uppercase letter, to match Clap's help for autogenerated arguments (eg. --help) * Update guide to account for argument help text starting with an uppercase letter * Add shortened aliases for `tx raw` commands Co-authored-by: Sean Chen <seanchen11235@gmail.com> Co-authored-by: Adi Seredinschi <adi@informal.systems> Co-authored-by: Romain Ruetschi <romain@informal.systems>
Closes: #2239
Description
This PR adds flags instead of positional arguments to all CLI commands. Long flags have been used in order to avoid conflicts or confusing flags.
WIP
PR author checklist:
unclog
.Added tests: integration (for Hermes) or unit/mock tests (for modules).guide/
).Reviewer checklist:
Files changed
in the GitHub PR explorer.