summaryrefslogtreecommitdiffstats
path: root/vendor/clap_complete/examples/dynamic.rs
blob: ccaf7d8ad2d434c839e4b9731aaa7c9b5e542b3f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use clap::FromArgMatches;
use clap::Subcommand;

fn command() -> clap::Command {
    let cmd = clap::Command::new("dynamic")
        .arg(
            clap::Arg::new("input")
                .long("input")
                .short('i')
                .value_hint(clap::ValueHint::FilePath),
        )
        .arg(
            clap::Arg::new("format")
                .long("format")
                .short('F')
                .value_parser(["json", "yaml", "toml"]),
        )
        .args_conflicts_with_subcommands(true);
    clap_complete::dynamic::shells::CompleteCommand::augment_subcommands(cmd)
}

fn main() {
    let cmd = command();
    let matches = cmd.get_matches();
    if let Ok(completions) =
        clap_complete::dynamic::shells::CompleteCommand::from_arg_matches(&matches)
    {
        completions.complete(&mut command());
    } else {
        println!("{matches:#?}");
    }
}

#[test]
fn verify_cli() {
    command().debug_assert();
}