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);
|
2023-07-19 02:50:34 +00:00
|
|
|
clap_complete::dynamic::shells::CompleteCommand::augment_subcommands(cmd)
|
2022-04-15 21:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let cmd = command();
|
|
|
|
let matches = cmd.get_matches();
|
|
|
|
if let Ok(completions) =
|
2023-07-19 02:50:34 +00:00
|
|
|
clap_complete::dynamic::shells::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
|
|
|
}
|