Crate clap_autocomplete
source ·Expand description
Easy to integrate shell completion for Clap. Tries to choose the user’s shell and put completion files in the appropriate locations.
For best results, please add ValueHint
s to every argument that takes a value.
This greatly improves the shell completion experience.
Examples
// Create a command from the crate metadata
let mut command = clap::command!();
// Register `complete` subcommand
command = clap_autocomplete::add_subcommand(command);
// Add other arguments and subcommands
let command_copy = command.clone();
// Resolve the matches
let matches = command.get_matches();
if let Some(result) = clap_autocomplete::test_subcommand(&matches, command_copy) {
if let Err(err) = result {
eprintln!("Insufficient permissions: {err}");
std::process::exit(1);
} else {
std::process::exit(0);
}
} else {
// Continue with the application logic
}
Functions
Add the
complete
subcommand to your Command
.Check the
ArgMatches
for the subcommand added by add_subcommand
.