Skip to main content

render_completion

Function render_completion 

Source
pub fn render_completion(
    shell: Shell,
    program: &str,
    registry: &Registry,
) -> String
Expand description

Generate a shell completion script for a registry of commands.

The generated script hooks into the shell’s native completion mechanism. Source it in your shell profile to enable tab-completion for your tool.

§Arguments

  • shell — the target shell
  • program — the program name as it appears in PATH (e.g. "mytool")
  • registry — the crate::query::Registry containing all commands

§Examples

let registry = Registry::new(vec![
    Command::builder("deploy")
        .flag(Flag::builder("env").takes_value().choices(["prod", "staging"]).build().unwrap())
        .build().unwrap(),
    Command::builder("status").build().unwrap(),
]);

let script = render_completion(Shell::Bash, "mytool", &registry);
assert!(script.contains("mytool"));
assert!(script.contains("deploy"));
assert!(script.contains("status"));