generate all completions by default

This commit is contained in:
shimun 2020-10-27 15:03:05 +01:00
parent 06f97592c1
commit d8aca91136
Signed by: shimun
GPG Key ID: E81D8382DC2F971B
2 changed files with 22 additions and 8 deletions

View File

@ -632,12 +632,25 @@ pub fn run_cli() -> Fido2LuksResult<()> {
}
},
Command::GenerateCompletions { shell, out_dir } => {
// zsh won't work atm https://github.com/clap-rs/clap/issues/1822
if let Some(s) = shell {
if s.as_str() == "zsh" {
unimplemented!("zsh completions are broken atm: see https://github.com/clap-rs/clap/issues/1822")
}
}
for variant in Shell::variants().iter().filter(|v| *v != &"zsh") {
if let Some(s) = shell {
if *variant != s.as_str() {
break;
}
}
Args::clap().gen_completions(
env!("CARGO_PKG_NAME"),
Shell::from_str(shell.as_str())
Shell::from_str(variant)
.expect("structopt shouldn't allow us to reach this point"),
&out_dir,
);
}
Ok(())
}
}

View File

@ -259,11 +259,12 @@ pub enum Command {
Connected,
Token(TokenCommand),
/// Generate bash completion scripts
/// Example: fido2luks completions --shell bash /usr/share/bash-completion/completions
#[structopt(name = "completions", setting = AppSettings::Hidden)]
GenerateCompletions {
/// Shell to generate completions for
#[structopt(possible_values = &Shell::variants()[..])]
shell: String,
#[structopt(short = "s", long = "shell",possible_values = &Shell::variants()[..])]
shell: Option<String>,
out_dir: PathBuf,
},
}