Skip to content

Commit

Permalink
feat(anvil): add shell completions subcommand (#2485)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Jul 27, 2022
1 parent e8e351e commit e37e434
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion anvil/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ clap = { version = "3.0.10", features = [
"env",
"wrap_help",
], optional = true }
clap_complete = { version = "3.0.4", optional = true }
async-trait = "0.1.53"
chrono = "0.4.19"
auto_impl = "0.5.0"
Expand All @@ -77,5 +78,5 @@ tokio = { version = "1", features = ["full"] }

[features]
default = ["cli"]
cmd = ["foundry-common", "forge", "clap", "ctrlc", "anvil-server/clap"]
cmd = ["foundry-common", "forge", "clap", "clap_complete", "ctrlc", "anvil-server/clap"]
cli = ["tokio/full", "cmd", "fdlimit"]
29 changes: 28 additions & 1 deletion anvil/src/anvil.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
//! The `anvil` cli
use anvil::cmd::NodeArgs;
use clap::Parser;
use clap::{CommandFactory, Parser, Subcommand};

/// A fast local Ethereum development node.
#[derive(Debug, Parser)]
#[clap(name = "anvil", version = anvil::VERSION_MESSAGE)]
pub struct App {
#[clap(flatten)]
pub node: NodeArgs,

#[clap(subcommand)]
pub cmd: Option<Commands>,
}

#[derive(Clone, Debug, Subcommand)]
pub enum Commands {
#[clap(visible_alias = "com", about = "Generate shell completions script.")]
Completions {
#[clap(arg_enum)]
shell: clap_complete::Shell,
},
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = App::parse();

if let Some(ref cmd) = app.cmd {
match cmd {
Commands::Completions { shell } => {
clap_complete::generate(
*shell,
&mut App::command(),
"anvil",
&mut std::io::stdout(),
);
}
}
return Ok(())
}

let _ = fdlimit::raise_fd_limit();
app.node.run().await?;

Expand Down

0 comments on commit e37e434

Please sign in to comment.