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:
MrSnowy
2026-03-17 18:17:51 +00:00
committed by Alex
parent 60244b60dd
commit 96b986a0a0
4 changed files with 20 additions and 1 deletions
+10
View File
@@ -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
View File
@@ -1,3 +1,4 @@
pub(crate) mod completions;
pub(crate) mod convert_db;
pub(crate) mod init;
pub(crate) mod repair;
+5 -1
View File
@@ -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 },
}
// ---------------------------
+4
View File
@@ -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,
}
}