add subcommand to generate bash completions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
2266754a95
commit
e1f762ddc9
2
PKGBUILD
2
PKGBUILD
@ -11,8 +11,10 @@ license=('MPL-2.0')
|
||||
|
||||
build() {
|
||||
cargo build --release --locked --all-features --target-dir=target
|
||||
./target/release/fido2luks completions bash target
|
||||
}
|
||||
|
||||
package() {
|
||||
install -Dm 755 target/release/${pkgname} -t "${pkgdir}/usr/bin"
|
||||
install -Dm 644 target/fido2luks.bash "${pkgdir}/usr/share/bash-completion/completions/fido2luks"
|
||||
}
|
||||
|
21
src/cli.rs
21
src/cli.rs
@ -1,6 +1,7 @@
|
||||
use crate::error::*;
|
||||
use crate::*;
|
||||
|
||||
use structopt::clap::{AppSettings, Shell};
|
||||
use structopt::StructOpt;
|
||||
|
||||
use ctap::{FidoCredential, FidoErrorKind};
|
||||
@ -303,6 +304,14 @@ pub enum Command {
|
||||
#[structopt(name = "connected")]
|
||||
Connected,
|
||||
Token(TokenCommand),
|
||||
/// Generate bash completion scripts
|
||||
#[structopt(name = "completions", setting = AppSettings::Hidden)]
|
||||
GenerateCompletions {
|
||||
/// Shell to generate completions for: bash, fish
|
||||
#[structopt(possible_values = &["bash", "fish"])]
|
||||
shell: String,
|
||||
out_dir: PathBuf,
|
||||
},
|
||||
}
|
||||
|
||||
///LUKS2 token related operations
|
||||
@ -725,5 +734,17 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
},
|
||||
Command::GenerateCompletions { shell, out_dir } => {
|
||||
Args::clap().gen_completions(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
match shell.as_ref() {
|
||||
"bash" => Shell::Bash,
|
||||
"fish" => Shell::Fish,
|
||||
_ => unreachable!("structopt shouldn't allow us to reach this point"),
|
||||
},
|
||||
&out_dir,
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user