Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(anvil): add shell completions subcommand #2485

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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