Crate clap_complete
source ·Expand description
§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::{Command, Arg, ValueHint, value_parser, ArgAction};
use clap_complete::aot::{generate, Generator, Shell};
use std::io;
fn build_cli() -> Command {
Command::new("example")
.arg(Arg::new("file")
.help("some input file")
.value_hint(ValueHint::AnyPath),
)
.arg(
Arg::new("generator")
.long("generate")
.action(ArgAction::Set)
.value_parser(value_parser!(Shell)),
)
}
fn print_completions<G: Generator>(gen: G, cmd: &mut Command) {
generate(gen, cmd, cmd.get_name().to_string(), &mut io::stdout());
}
fn main() {
let matches = build_cli().get_matches();
if let Some(generator) = matches.get_one::<Shell>("generator").copied() {
let mut cmd = build_cli();
eprintln!("Generating completion file for {generator}...");
print_completions(generator, &mut cmd);
}
}
§clap_complete
Shell completion generation for
clap
Dual-licensed under Apache 2.0 or MIT.
§About
§Related Projects
- clap_complete_fig for fig shell completion support
- clap_complete_nushell for nushell shell completion support
Re-exports§
pub use command::CompleteArgs;
unstable-command
pub use command::CompleteCommand;
unstable-command
pub use engine::ArgValueCompleter;
unstable-dynamic
pub use engine::PathCompleter;
unstable-dynamic
pub use env::CompleteEnv;
unstable-dynamic
pub use aot::generate;
pub use aot::generate_to;
pub use aot::Generator;
pub use aot::Shell;
Modules§
- Prebuilt completions
- command
unstable-command
<bin> complete
completion integration - engine
unstable-dynamic
clap
-native completion system - env
unstable-dynamic
COMPLETE=$SHELL <bin>
completion integration - Deprecated, see
aot
- Deprecated, see
aot
Structs§
- ArgValue
Candidates unstable-dynamic
ExtendArg
with aValueCandidates
- Completion
Candidate unstable-dynamic
A shell-agnostic completion candidate
Enums§
- Provide shell with hint on how to complete an argument.