Merge pull request #93 from dyc3/shell-completions

add shell completion generation
This commit is contained in:
Carson McManus 2021-08-17 18:16:24 -04:00 committed by GitHub
commit dc18f3a7ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,7 @@
extern crate rpassword;
use clap::{crate_version, App, Arg};
use clap::{crate_version, App, Arg, Shell};
use log::*;
use std::str::FromStr;
use std::{
io::{stdout, Write},
path::Path,
@ -20,8 +21,8 @@ mod accountmanager;
mod demos;
mod tui;
fn main() {
let matches = App::new("steamguard-cli")
fn cli() -> App<'static, 'static> {
App::new("steamguard-cli")
.version(crate_version!())
.bin_name("steamguard")
.author("dyc3 (Carson McManus)")
@ -62,6 +63,16 @@ fn main() {
.takes_value(false)
.multiple(true)
)
.subcommand(
App::new("completion")
.about("Generate shell completions")
.arg(
Arg::with_name("shell")
.long("shell")
.takes_value(true)
.possible_values(&Shell::variants())
)
)
.subcommand(
App::new("trade")
.about("Interactive interface for trade confirmations")
@ -98,7 +109,10 @@ fn main() {
.takes_value(false)
)
)
.get_matches();
}
fn main() {
let matches = cli().get_matches();
let verbosity = matches.occurrences_of("verbosity") as usize + 2;
stderrlog::new()
@ -114,6 +128,14 @@ fn main() {
}
return;
}
if let Some(completion_matches) = matches.subcommand_matches("completion") {
cli().gen_completions_to(
"steamguard",
Shell::from_str(completion_matches.value_of("shell").unwrap()).unwrap(),
&mut std::io::stdout(),
);
return;
}
let mafiles_dir = if matches.occurrences_of("mafiles-path") > 0 {
matches.value_of("mafiles-path").unwrap().into()