mirror of
https://github.com/deuxfleurs-org/garage.git
synced 2026-07-26 07:58:14 +00:00
Add completions sub-command for generating shell completions (#1386)
Made a quick pr to add a sub-command called completions for generating shell completions, was going pretty crazy that this wasn't a thing :P. Tried my best to do everything properly, let me know if I need to change something, I tested it and it works perfectly. Co-authored-by: MrSnowy <snow@mrsnowy.dev> Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/1386 Reviewed-by: Alex <lx@deuxfleurs.fr> Co-authored-by: MrSnowy <mrsnowy@noreply.localhost> Co-committed-by: MrSnowy <mrsnowy@noreply.localhost>
This commit is contained in:
@@ -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());
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub(crate) mod completions;
|
||||
pub(crate) mod convert_db;
|
||||
pub(crate) mod init;
|
||||
pub(crate) mod repair;
|
||||
|
||||
@@ -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 },
|
||||
}
|
||||
|
||||
// ---------------------------
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user