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(
11 name = "completions",
12 about = "Generate shell completions",
13 after_help = "Examples:
14 auths completions bash # Print Bash completions
15 auths completions zsh # Print Zsh completions
16 auths completions fish # Print Fish completions
17 auths completions powershell # Print PowerShell completions
18
19Installation:
20 Bash: auths completions bash > ~/.local/share/bash-completion/completions/auths
21 Zsh: auths completions zsh > ~/.zfunc/_auths
22 Fish: auths completions fish > ~/.config/fish/completions/auths.fish
23 PowerShell: auths completions powershell > auths.ps1
24
25After installation, restart your shell or source the completion file.
26
27Related:
28 auths --help — Show all commands
29 auths <command> -h — Show command help"
30)]
31pub struct CompletionsCommand {
32 #[arg(value_enum)]
34 pub shell: Shell,
35}
36
37pub fn handle_completions<C: CommandFactory>(cmd: CompletionsCommand) -> Result<()> {
55 let mut command = C::command();
56 let name = command.get_name().to_string();
57 generate(cmd.shell, &mut command, name, &mut io::stdout());
58 Ok(())
59}
60
61impl crate::commands::executable::ExecutableCommand for CompletionsCommand {
62 fn execute(&self, _ctx: &crate::config::CliConfig) -> anyhow::Result<()> {
63 handle_completions::<crate::cli::AuthsCli>(self.clone())
64 }
65}