30 lines
865 B
Rust
30 lines
865 B
Rust
use clap::{Command, Arg, value_parser, ArgAction};
|
|
use clap_complete::{generate, Generator, Shell};
|
|
use std::io;
|
|
|
|
use tiempo::cli::make_cli;
|
|
|
|
fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
|
|
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
|
|
}
|
|
|
|
fn main() {
|
|
let command = Command::new("example")
|
|
.arg(
|
|
Arg::new("generator")
|
|
.long("generate")
|
|
.action(ArgAction::Set)
|
|
.value_parser(value_parser!(Shell)),
|
|
);
|
|
|
|
let matches = command.get_matches();
|
|
|
|
if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
|
|
let mut cmd = make_cli();
|
|
eprintln!("Generating completion file for {}...", generator);
|
|
print_completions(generator, &mut cmd);
|
|
} else {
|
|
eprintln!("Specified generator does not exist");
|
|
}
|
|
}
|