Upgrade clap, using clap_derive to define subcommands and arguments#661
Draft
eval-exec wants to merge 21 commits intonervosnetwork:developfrom
Draft
Upgrade clap, using clap_derive to define subcommands and arguments#661eval-exec wants to merge 21 commits intonervosnetwork:developfrom
eval-exec wants to merge 21 commits intonervosnetwork:developfrom
Conversation
4b7a653 to
d8c3076
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR upgrades the CLI argument parsing stack from clap = 3.0.0-beta.1 to clap 4 and migrates most subcommands to clap_derive (Parser/Subcommand/Args) for longer-term maintainability.
Changes:
- Upgrade
clapto v4 and replaceclap_generatewithclap_complete. - Refactor subcommand definitions (
wallet,util,tx,sudt, etc.) from manualApp/Argbuilders to derive-based command/args structs. - Add small compatibility helpers (e.g.,
ArgMatchesExt,ArgValidatorExt) to smooth the clap v3→v4 API transition.
Reviewed changes
Copilot reviewed 24 out of 25 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/other.rs | Adds ArgMatches extension usage and marks legacy helpers as dead-code during migration. |
| src/utils/mod.rs | Exposes new utils::command module. |
| src/utils/completer.rs | Updates interactive completer to use clap::Command API. |
| src/utils/command.rs | Adds a small CommandHelpExt helper trait. |
| src/utils/arg.rs | Updates Arg builders for clap v4 and introduces a validator compatibility extension. |
| src/utils/arg_parser.rs | Adds ArgMatchesExt and updates match accessors for clap v4. |
| src/subcommands/wallet.rs | Migrates wallet subcommands and args to clap derive. |
| src/subcommands/util.rs | Migrates util subcommands to clap derive and switches completions generation to clap_complete. |
| src/subcommands/tx.rs | Migrates tx subcommands/args to clap derive and updates parsing logic accordingly. |
| src/subcommands/sudt.rs | Migrates sudt subcommands/args to clap derive. |
| src/subcommands/pubsub.rs | Migrates subscribe command to clap derive and updates topic parsing. |
| src/subcommands/plugin.rs | Migrates plugin management commands to clap derive. |
| src/subcommands/molecule.rs | Migrates molecule encode/decode utilities to clap derive. |
| src/subcommands/mod.rs | Updates shared arg helpers for clap v4 (and introduces ArgMatchesExt usage). |
| src/subcommands/mock_tx.rs | Migrates mock-tx commands to clap derive and refactors helper closures accordingly. |
| src/subcommands/deploy/mod.rs | Migrates deploy subcommands/args to clap derive. |
| src/subcommands/dao/command.rs | Migrates dao commands/args to clap derive and refactors argument parsing. |
| src/subcommands/api_server.rs | Migrates server command to clap derive. |
| src/subcommands/account.rs | Migrates account commands to clap derive and refactors parsing/validation. |
| src/main.rs | Updates top-level CLI construction for clap v4 and introduces derive-based global args via cli::CliArgs. |
| src/interactive.rs | Updates interactive parser/completion to clap v4 Command APIs. |
| src/cli.rs | Introduces derive-based global CLI args (url, output-format, no-color, etc.). |
| Cargo.toml | Upgrades to clap 4 and adds clap_complete. |
| Cargo.lock | Updates dependency graph for clap v4 ecosystem. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+228
to
233
| let version_short: &'static str = Box::leak(version_short.to_owned().into_boxed_str()); | ||
| let version_long: &'static str = Box::leak(version_long.to_owned().into_boxed_str()); | ||
| let mut cmd = cli::CliArgs::command(); | ||
| cmd = cmd | ||
| .version(version_short) | ||
| .long_version(version_long) |
Comment on lines
+48
to
+64
| #[derive(Args, Debug)] | ||
| pub struct PubSubListArgs { | ||
| #[arg(long, value_parser = parse_socket)] | ||
| pub tcp: String, | ||
| #[arg( | ||
| short = 't', | ||
| value_parser = [ | ||
| "new_tip_header", | ||
| "new_tip_block", | ||
| "new_transaction", | ||
| "proposed_transaction", | ||
| "rejected_transaction", | ||
| ], | ||
| action = ArgAction::Append | ||
| )] | ||
| pub topics: Vec<String>, | ||
| } |
| } | ||
|
|
||
| fn parse_address(input: &str) -> Result<String, String> { | ||
| AddressParser::default() |
Comment on lines
+164
to
+168
| #[derive(Args, Debug)] | ||
| pub struct WalletGetCapacityArgs { | ||
| #[arg(long, value_parser = parse_address)] | ||
| pub address: Option<String>, | ||
| #[arg(long = "pubkey", id = "pubkey")] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For long-term maintenance, we should upgrade
clap = "=3.0.0-beta.1"toclap 4