2022-04-15 21:08:11 +00:00
|
|
|
use clap::FromArgMatches;
|
|
|
|
use clap::Subcommand;
|
|
|
|
|
2022-08-15 19:29:46 +00:00
|
|
|
fn command() -> clap::Command {
|
2022-04-15 21:08:11 +00:00
|
|
|
let cmd = clap::Command::new("dynamic")
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("input")
|
2022-09-02 18:11:11 +00:00
|
|
|
.long("input")
|
2022-04-15 21:08:11 +00:00
|
|
|
.short('i')
|
|
|
|
.value_hint(clap::ValueHint::FilePath),
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
clap::Arg::new("format")
|
2022-09-02 18:11:11 +00:00
|
|
|
.long("format")
|
2022-04-15 21:08:11 +00:00
|
|
|
.short('F')
|
2022-05-24 01:16:02 +00:00
|
|
|
.value_parser(["json", "yaml", "toml"]),
|
2022-04-15 21:08:11 +00:00
|
|
|
)
|
|
|
|
.args_conflicts_with_subcommands(true);
|
2024-08-09 20:14:33 +00:00
|
|
|
clap_complete::dynamic::CompleteCommand::augment_subcommands(cmd)
|
2022-04-15 21:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let cmd = command();
|
|
|
|
let matches = cmd.get_matches();
|
2024-08-09 20:14:33 +00:00
|
|
|
if let Ok(completions) = clap_complete::dynamic::CompleteCommand::from_arg_matches(&matches) {
|
2022-04-15 21:08:11 +00:00
|
|
|
completions.complete(&mut command());
|
|
|
|
} else {
|
2023-05-04 19:53:36 +00:00
|
|
|
println!("{matches:#?}");
|
2022-04-15 21:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn verify_cli() {
|
2022-09-02 18:11:11 +00:00
|
|
|
command().debug_assert();
|
2022-04-15 21:08:11 +00:00
|
|
|
}
|