Skip to content

Commit

Permalink
chore: update clap 4 argument parser (#3405)
Browse files Browse the repository at this point in the history
* chore: update clap 4 argument parser

* fix: parse correct range

* test: add --help test coverage for all subcommands
  • Loading branch information
mattsse authored Sep 29, 2022
1 parent bee20ef commit 7257375
Show file tree
Hide file tree
Showing 31 changed files with 267 additions and 91 deletions.
137 changes: 114 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ yansi = "0.5.1"
tempfile = "3.3.0"

# cli
clap = { version = "3.0.10", features = ["derive", "env", "wrap_help"], optional = true }
clap_complete = { version = "3.0.4", optional = true }
clap = { version = "4.0", features = ["derive", "env", "wrap_help"], optional = true }
clap_complete = { version = "4.0", optional = true }
chrono = "0.4.19"
auto_impl = "0.5.0"
ctrlc = { version = "3", optional = true }
fdlimit = { version = "0.2.1", optional = true }
clap_complete_fig = "3.2.4"
clap_complete_fig = "4.0"
ethereum-forkid = "0.10.0"

# ethers
Expand Down
2 changes: 1 addition & 1 deletion anvil/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ serde = { version = "1.0.136", features = ["derive"] }
async-trait = "0.1.53"
thiserror = "1.0.34"

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

[features]
Expand Down
20 changes: 18 additions & 2 deletions anvil/src/anvil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ pub struct App {
pub cmd: Option<Commands>,
}

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

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn can_parse_help() {
let _: App = App::parse_from(["anvil", "--help"]);
}

#[test]
fn can_parse_completions() {
let args: App = App::parse_from(["anvil", "completions", "bash"]);
assert_eq!(args.cmd, Some(Commands::Completions { shell: clap_complete::Shell::Bash }));
}
}
Loading

0 comments on commit 7257375

Please sign in to comment.