Skip to content

Commit

Permalink
feat: cli completions
Browse files Browse the repository at this point in the history
  • Loading branch information
zilayo committed Sep 15, 2024
1 parent c989c8e commit 335d84b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 19 deletions.
63 changes: 46 additions & 17 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 cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ base64 = "0.21"
bincode = "1.3.3"
cargo_toml = "0.19.2"
chrono = "0.4.19"
clap = { version = "4.2.4", features = ["derive"] }
clap = { version = "4.5.17", features = ["derive"] }
clap_complete = "4.5.26"
dirs = "4.0"
flate2 = "1.0.19"
heck = "0.4.0"
Expand Down
17 changes: 16 additions & 1 deletion cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use anchor_lang_idl::convert::convert_idl;
use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTypeDefTy};
use anyhow::{anyhow, Context, Result};
use checks::{check_anchor_version, check_idl_build_feature, check_overflow};
use clap::Parser;
use clap::{CommandFactory, Parser};
use clap_complete::generate;
use dirs::home_dir;
use flate2::read::GzDecoder;
use flate2::read::ZlibDecoder;
Expand Down Expand Up @@ -365,6 +366,11 @@ pub enum Command {
#[clap(long)]
idl: Option<String>,
},
/// Generates shell completions.
Completions {
#[clap(value_enum)]
shell: clap_complete::Shell,
},
}

#[derive(Debug, Parser)]
Expand Down Expand Up @@ -924,6 +930,15 @@ fn process_command(opts: Opts) -> Result<()> {
address,
idl,
} => account(&opts.cfg_override, account_type, address, idl),
Command::Completions { shell } => {
generate(
shell,
&mut Opts::command(),
"anchor",
&mut std::io::stdout(),
);
Ok(())
}
}
}

Expand Down

0 comments on commit 335d84b

Please sign in to comment.