clap_complete_command 0.3.0

Reduces boilerplate for adding a completion command to Clap
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use clap::{Arg, Command};

fn build_cli() -> Command<'static> {
    Command::new(env!("CARGO_PKG_NAME")).arg(
        Arg::new("completion")
            .help("Generate shell completions")
            .possible_values(clap_complete_command::Shell::possible_values()),
    )
}

fn main() {
    let matches = build_cli().get_matches();

    if let Ok(shell) = matches.value_of_t::<clap_complete_command::Shell>("completion") {
        let mut command = build_cli();
        shell.generate(&mut command, &mut std::io::stdout());
    }
}