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 ValueHints 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_
subcommand - Add the
completesubcommand to yourCommand. - test_
subcommand - Check the
ArgMatchesfor the subcommand added byadd_subcommand.