Skip to main content

shell_complete

Function shell_complete 

Source
pub fn shell_complete(
    cmd: &dyn CommandLike,
    prog_name: &str,
    complete_var: &str,
)
Expand description

Main shell completion entry point.

This function should be called when the completion environment variable is set. It parses the completion arguments, generates completions, and outputs them in the appropriate format for the shell.

§Arguments

  • cmd - The root command to complete for
  • prog_name - The program name
  • complete_var - The environment variable name that triggers completion

§Example

use click::completion::shell_complete;
use click::command::Command;
use std::env;

let cmd = Command::new("myapp").build();

// In your main(), check if completion is requested
if let Ok(shell) = env::var("_MYAPP_COMPLETE") {
    shell_complete(&cmd, "myapp", "_MYAPP_COMPLETE");
    return;
}