auths_cli/commands/
completions.rs1use anyhow::Result;
4use clap::{CommandFactory, Parser};
5use clap_complete::{Shell, generate};
6use std::io;
7
8#[derive(Parser, Debug, Clone)]
10#[command(name = "completions", about = "Generate shell completions")]
11pub struct CompletionsCommand {
12 #[arg(value_enum)]
14 pub shell: Shell,
15}
16
17pub fn handle_completions<C: CommandFactory>(cmd: CompletionsCommand) -> Result<()> {
35 let mut command = C::command();
36 let name = command.get_name().to_string();
37 generate(cmd.shell, &mut command, name, &mut io::stdout());
38 Ok(())
39}
40
41impl crate::commands::executable::ExecutableCommand for CompletionsCommand {
42 fn execute(&self, _ctx: &crate::config::CliConfig) -> anyhow::Result<()> {
43 handle_completions::<crate::cli::AuthsCli>(self.clone())
44 }
45}