Skip to content

Commit 7257375

Browse files
authored
chore: update clap 4 argument parser (#3405)
* chore: update clap 4 argument parser * fix: parse correct range * test: add --help test coverage for all subcommands
1 parent bee20ef commit 7257375

31 files changed

+267
-91
lines changed

Cargo.lock

Lines changed: 114 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

anvil/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ yansi = "0.5.1"
5757
tempfile = "3.3.0"
5858

5959
# cli
60-
clap = { version = "3.0.10", features = ["derive", "env", "wrap_help"], optional = true }
61-
clap_complete = { version = "3.0.4", optional = true }
60+
clap = { version = "4.0", features = ["derive", "env", "wrap_help"], optional = true }
61+
clap_complete = { version = "4.0", optional = true }
6262
chrono = "0.4.19"
6363
auto_impl = "0.5.0"
6464
ctrlc = { version = "3", optional = true }
6565
fdlimit = { version = "0.2.1", optional = true }
66-
clap_complete_fig = "3.2.4"
66+
clap_complete_fig = "4.0"
6767
ethereum-forkid = "0.10.0"
6868

6969
# ethers

anvil/server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ serde = { version = "1.0.136", features = ["derive"] }
3131
async-trait = "0.1.53"
3232
thiserror = "1.0.34"
3333

34-
clap = { version = "3.0.10", features = ["derive", "env"], optional = true }
34+
clap = { version = "4.0", features = ["derive", "env"], optional = true }
3535
pin-project = "1.0.12"
3636

3737
[features]

anvil/src/anvil.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ pub struct App {
1313
pub cmd: Option<Commands>,
1414
}
1515

16-
#[derive(Clone, Debug, Subcommand)]
16+
#[derive(Clone, Debug, Subcommand, Eq, PartialEq)]
1717
pub enum Commands {
1818
#[clap(visible_alias = "com", about = "Generate shell completions script.")]
1919
Completions {
20-
#[clap(arg_enum)]
20+
#[clap(value_enum)]
2121
shell: clap_complete::Shell,
2222
},
2323
#[clap(visible_alias = "fig", about = "Generate Fig autocompletion spec.")]
@@ -53,3 +53,19 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
5353

5454
Ok(())
5555
}
56+
57+
#[cfg(test)]
58+
mod tests {
59+
use super::*;
60+
61+
#[test]
62+
fn can_parse_help() {
63+
let _: App = App::parse_from(["anvil", "--help"]);
64+
}
65+
66+
#[test]
67+
fn can_parse_completions() {
68+
let args: App = App::parse_from(["anvil", "completions", "bash"]);
69+
assert_eq!(args.cmd, Some(Commands::Completions { shell: clap_complete::Shell::Bash }));
70+
}
71+
}

0 commit comments

Comments
 (0)