Skip to main content

Crate argument_completions

Crate argument_completions 

Source
Expand description

Shell completion generation for argument based command line interfaces.

This crate generates static completion scripts from a Cli description. The following shells are supported: bash, elvish, fish, nushell, PowerShell and zsh.

use argument::{Cli, Opt, ValueHint};
use argument_completions::Shell;

#[derive(Copy, Clone)]
enum Arg {
    Output,
}

static CLI: Cli<Arg> = Cli::new("demo").opts(&[Opt::new(Arg::Output)
    .short('o')
    .long("output")
    .value("FILE")
    .value_hint(ValueHint::FilePath)
    .help("Output file")]);

let script = Shell::Bash.generate(&CLI, "demo");
assert!(script.contains("complete -F _demo"));

To offer completions at runtime (eg: via --generate-completion SHELL), use Shell::NAMES as possible values and parse the shell with str::parse.

Structs§

UnknownShellError
Error returned when parsing an unknown shell name.

Enums§

Shell
The supported shells.