Skip to main content

gor/cmd/
completion.rs

1//! Implementation of the `gor completion` subcommand.
2//!
3//! Generates shell completion scripts for bash, zsh, fish, and PowerShell.
4
5#![allow(clippy::print_stdout)]
6
7use clap::CommandFactory;
8use clap_complete::{Generator, Shell};
9
10/// Run the `gor completion` subcommand.
11///
12/// # Errors
13///
14/// Returns an error if the shell type is not recognized.
15pub fn run(shell: &str) -> anyhow::Result<()> {
16    let shell = shell.parse::<Shell>().map_err(|_| {
17        anyhow::anyhow!("unknown shell '{shell}'. Supported shells: bash, zsh, fish, powershell")
18    })?;
19
20    let cmd = crate::cli::Args::command();
21    let name = cmd.get_name().to_string();
22    shell.generate(&cmd, &mut std::io::stdout());
23
24    tracing::info!("Generated {shell} completion script for {name}");
25    Ok(())
26}