diff --git a/src/garage/cli/local/completions.rs b/src/garage/cli/local/completions.rs new file mode 100644 index 00000000..58f58a40 --- /dev/null +++ b/src/garage/cli/local/completions.rs @@ -0,0 +1,10 @@ +use structopt::{clap::Shell, StructOpt}; + +use crate::Opt; + +pub(crate) fn generate_completions(shell: Shell) { + let mut command = Opt::clap(); + + let command_name = command.get_name().to_string(); + command.gen_completions_to(command_name, shell, &mut std::io::stdout()); +} diff --git a/src/garage/cli/local/mod.rs b/src/garage/cli/local/mod.rs index 476010b8..edd5e66c 100644 --- a/src/garage/cli/local/mod.rs +++ b/src/garage/cli/local/mod.rs @@ -1,3 +1,4 @@ +pub(crate) mod completions; pub(crate) mod convert_db; pub(crate) mod init; pub(crate) mod repair; diff --git a/src/garage/cli/structs.rs b/src/garage/cli/structs.rs index e7422721..f623c60d 100644 --- a/src/garage/cli/structs.rs +++ b/src/garage/cli/structs.rs @@ -1,4 +1,4 @@ -use structopt::StructOpt; +use structopt::{clap::Shell, StructOpt}; use garage_util::version::garage_version; @@ -77,6 +77,10 @@ pub enum Command { #[structopt(default_value = "null")] payload: String, }, + + /// Generate completions for a shell + #[structopt(name = "completions", version = garage_version())] + Completions { shell: Shell }, } // --------------------------- diff --git a/src/garage/main.rs b/src/garage/main.rs index 0ab64086..62d10c82 100644 --- a/src/garage/main.rs +++ b/src/garage/main.rs @@ -177,6 +177,10 @@ async fn run(opt: Opt) -> Result<(), Error> { ); Ok(()) } + Command::Completions { shell } => { + cli::local::completions::generate_completions(shell); + Ok(()) + } _ => cli_command(opt).await, } }