Skip to main content

sc/cli/commands/
completions.rs

1//! Shell completions command implementation.
2
3use crate::cli::{Cli, Shell};
4use crate::error::Result;
5use clap::CommandFactory;
6use clap_complete::{generate, shells};
7use std::io;
8
9/// Generate shell completions for the specified shell.
10pub fn execute(shell: &Shell) -> Result<()> {
11    let mut cmd = Cli::command();
12
13    match shell {
14        Shell::Bash => generate(shells::Bash, &mut cmd, "sc", &mut io::stdout()),
15        Shell::Zsh => generate(shells::Zsh, &mut cmd, "sc", &mut io::stdout()),
16        Shell::Fish => generate(shells::Fish, &mut cmd, "sc", &mut io::stdout()),
17        Shell::PowerShell => generate(shells::PowerShell, &mut cmd, "sc", &mut io::stdout()),
18        Shell::Elvish => generate(shells::Elvish, &mut cmd, "sc", &mut io::stdout()),
19    }
20
21    Ok(())
22}