Crate clap_generate[−][src]
Expand description
clap_generate
Generates completions (and other things) for clap
based CLIs
Quick Start
- For generating at compile-time, see
generate_to
- For generating at runtime, see
generate
Shell
is a convenience enum
for an argument value type that implements Generator
for each natively-supported shell type.
Example
use clap::{App, AppSettings, Arg, ValueHint};
use clap_generate::{generate, Generator, Shell};
use std::io;
fn build_cli() -> App<'static> {
App::new("example")
.arg(Arg::new("file")
.help("some input file")
.value_hint(ValueHint::AnyPath),
)
.arg(
Arg::new("generator")
.long("generate")
.possible_values(Shell::possible_values()),
)
}
fn print_completions<G: Generator>(gen: G, app: &mut App) {
generate(gen, app, app.get_name().to_string(), &mut io::stdout());
}
fn main() {
let matches = build_cli().get_matches();
if let Ok(generator) = matches.value_of_t::<Shell>("generator") {
let mut app = build_cli();
eprintln!("Generating completion file for {}...", generator);
print_completions(generator, &mut app);
}
}
Modules
Contains some popular generators
Helpers for writing generators
Enums
Shell with auto-generated completion script available.
Traits
Generator trait which can be used to write generators
Functions
Generate a completions file for a specified shell at runtime.
Generate a completions file for a specified shell at compile-time.