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.


// 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}");
    } else {
} else {
    // Continue with the application logic