Skip to content

Upgrade clap, using clap_derive to define subcommands and arguments#661

Draft
eval-exec wants to merge 21 commits intonervosnetwork:developfrom
eval-exec:ckb-cli.clap-upgrade
Draft

Upgrade clap, using clap_derive to define subcommands and arguments#661
eval-exec wants to merge 21 commits intonervosnetwork:developfrom
eval-exec:ckb-cli.clap-upgrade

Conversation

@eval-exec
Copy link
Copy Markdown
Collaborator

@eval-exec eval-exec commented Jan 30, 2026

For long-term maintenance, we should upgrade clap = "=3.0.0-beta.1" to clap 4

Copilot AI review requested due to automatic review settings May 6, 2026 06:39
@eval-exec eval-exec force-pushed the ckb-cli.clap-upgrade branch from 4b7a653 to d8c3076 Compare May 6, 2026 06:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 clap to v4 and replace clap_generate with clap_complete.
  • Refactor subcommand definitions (wallet, util, tx, sudt, etc.) from manual App/Arg builders 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 thread src/main.rs
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 thread src/subcommands/pubsub.rs
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 thread src/subcommands/wallet.rs
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")]
@eval-exec eval-exec marked this pull request as draft May 6, 2026 06:46
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