Skip to content

Commit

Permalink
Add support for generating completion scripts for shells other than bash
Browse files Browse the repository at this point in the history
This change adds support for generating completion scripts for shells
other than bash to the shell-complete utility program. Specifically, it
now expects the shell to generate such a script for as its first
positional argument.
We do not add tests for the completion functionality for the newly
supported shells. Such tests are a pain to write, they are unlikely to
cover anything that the clap test suite does not already, and we simply
do not have all such shells available.
  • Loading branch information
d-e-s-o committed Mar 21, 2021
1 parent b8018cc commit 5ce697d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Unreleased
Storage devices
- Renamed the `--{no-,}{numlock,capslock,scrollock}` options of the `config
set` command to `--{no-,}{num-lock,caps-lock,scroll-lock}`
- Added support for generating completion scripts for shells other than
`bash`
- Bumped `nitrokey` dependency to `0.8.0`
- Bumped `structopt` dependency to `0.3.21`

Expand Down
9 changes: 6 additions & 3 deletions var/shell-complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ mod nitrocli {
include!("../src/args.rs");
}

/// Generate a bash completion script for nitrocli.
/// Generate a shell completion script for nitrocli.
///
/// The script will be emitted to standard output.
#[derive(Debug, structopt::StructOpt)]
struct Args {
/// The command for which to generate the bash completion script.
/// The shell for which to generate a completion script for.
#[structopt(possible_values = &clap::Shell::variants())]
shell: clap::Shell,
/// The command for which to generate the shell completion script.
#[structopt(default_value = "nitrocli")]
command: String,
}
Expand All @@ -51,7 +54,7 @@ where

fn main() {
let args = Args::from_args();
generate_for_shell(&args.command, clap::Shell::Bash, &mut io::stdout())
generate_for_shell(&args.command, args.shell, &mut io::stdout())
}

#[cfg(test)]
Expand Down

0 comments on commit 5ce697d

Please sign in to comment.