-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Refactor and port CLI from Docopt to Clap (#2066) #6356
Conversation
It looks like @axelchalon signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
@@ -21,383 +21,941 @@ use dir; | |||
|
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.
warning: unused import:
dir
--> parity/cli/mod.rs:20:5
|
20 | use dir;
| ^^^
|
= note: #[warn(unused_imports)] on by default
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.
fixed
Can you wrap it to 100 or 120 characters per line? this function might be helpful
That's a huuuge improvement!
I can't talk for others, but I'm totally fine with this change I will review it further tomorrow |
Cool. |
Closes #2066 |
I would suggest that the help message for |
Yes, the This being said, I just noticed that some of those top-level options are actually only used for subcommands (namely all the "Import/export" options except for, afaik, "flag_no_seal_check"), so I moved them to the subcommand's options. Let me know if there are other top-level options that are subcommand-specific! I updated the gist of the |
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.
lgtm
} | ||
} | ||
|
||
CMD cmd_snapshot |
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.
Should those two be grouped together?
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.
what do you mean?
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.
like:
parity snapshot take
and parity snapshot restore
Right now while parity snapshot
is self-describing, I had to check the docs what parity restore
is supposed to do.
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.
yeah, makes sense! I too think it'd be better this way, but then the usage would change from the current version (currently it's parity snapshot
and parity restore
; I didn't change the name of the subcommands or options, simply refactored). It wouldn't be hard to find the new subcommand, but it'd be a breaking change in case people have scripts running with the current syntax for example. maybe we can keep this PR a refactoring one?
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.
A separate PR is fine for me, although we already break backward compatibility by disallowing options after the command name.
@5chdn please work with @axelchalon for the 1.8.0 release's changelog - this will break quite a lot of installations. |
parity account --help
,parity account list --help
. Their help messages are very scanty for now, so some (more) help would be welcome. The help messages of the subcommands are generated by clap.parity snapshot --chain=dev mysnapshot.dump
won't work; it needs to beparity --chain=dev snapshot mysnapshot.dump
. The --help message was modified to convey this:parity [options] snapshot <FILE>
for example. This is a breaking change, I believe. Likewise, subcommand-specific arguments aren't allowed before the subcommand anymore.argument value
syntax whenvalue
is the name of a subcommand; e.g.parity --ui-path signer
won't work becausesigner
is the name of a subcommand, and Clap parses this as running thesigner
subcommand with the global argumentui-path
having an empty value. For those special cases we need to use theargument=value
syntax:parity --ui-path=signer
. I edited the corresponding test. (also filed an issue on clap, Argument value should take precedence over subcommand with the same name clap-rs/clap#1031) [EDIT: Clap fixed the issue]parity account import
.flag_
s are CLI switches (boolean) such as (--no-config
),arg_
s take values (--chain dev
,<FILE>
). I renamed some arguments because of this.--can-restart
and--force-direct
from the help message because these flags are not parsed by clap but parsed beforehand, and the help message is generated based on clap arguments. If it is preferable to leave their help messages in the--help
output, let me know and we could add them to the clap flags (even though their values from the clap Args struct wouldn't be used anywhere).--password
argument depending on what command/subcommand it's for:arg_signer_sign_password
,arg_wallet_import_password
,arg_account_new_password
,arg_password
(the latter bing the only one of those arguments to be a vec), and removed the legacy optionflag_warp
, as its value was systematically the opposite offlag_no_warp
(both values are fetched from the config file entry "warp"); I switched to usingflag_no_warp
instead offlag_warp
on the one instance in the codebase whereflag_warp
as used. Also, the legacy flagflag_dapps_apis_all
is now like all the other flags abool
, not anOption<bool>
.config.toml
files inparity/cli
are only used for test purposes, so I moved them to atest
subfolder.--help
message for the options do not take into account the config file parameters; they are the built-in defaults. But I think it was also this way with docopt.--argument value1 value2
, although it would be possible to use commas as delimiters with clap instead.Here's the
--help
output: https://gist.github.com/axelchalon/71e1f34019771f444d8380b21a88e2c8Subcommand and subsubcommand
--help
output: https://gist.github.com/axelchalon/7a6762be783094a455a0e1b4a5181e88...and
--version
output: https://gist.github.com/axelchalon/2639d0a3b1628c57afd242ee3163c430