Merge pull request #93 from dyc3/shell-completions
add shell completion generation
This commit is contained in:
commit
dc18f3a7ab
1 changed files with 26 additions and 4 deletions
30
src/main.rs
30
src/main.rs
|
@ -1,6 +1,7 @@
|
||||||
extern crate rpassword;
|
extern crate rpassword;
|
||||||
use clap::{crate_version, App, Arg};
|
use clap::{crate_version, App, Arg, Shell};
|
||||||
use log::*;
|
use log::*;
|
||||||
|
use std::str::FromStr;
|
||||||
use std::{
|
use std::{
|
||||||
io::{stdout, Write},
|
io::{stdout, Write},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
@ -20,8 +21,8 @@ mod accountmanager;
|
||||||
mod demos;
|
mod demos;
|
||||||
mod tui;
|
mod tui;
|
||||||
|
|
||||||
fn main() {
|
fn cli() -> App<'static, 'static> {
|
||||||
let matches = App::new("steamguard-cli")
|
App::new("steamguard-cli")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.bin_name("steamguard")
|
.bin_name("steamguard")
|
||||||
.author("dyc3 (Carson McManus)")
|
.author("dyc3 (Carson McManus)")
|
||||||
|
@ -62,6 +63,16 @@ fn main() {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.multiple(true)
|
.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(
|
.subcommand(
|
||||||
App::new("trade")
|
App::new("trade")
|
||||||
.about("Interactive interface for trade confirmations")
|
.about("Interactive interface for trade confirmations")
|
||||||
|
@ -98,7 +109,10 @@ fn main() {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.get_matches();
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let matches = cli().get_matches();
|
||||||
|
|
||||||
let verbosity = matches.occurrences_of("verbosity") as usize + 2;
|
let verbosity = matches.occurrences_of("verbosity") as usize + 2;
|
||||||
stderrlog::new()
|
stderrlog::new()
|
||||||
|
@ -114,6 +128,14 @@ fn main() {
|
||||||
}
|
}
|
||||||
return;
|
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 {
|
let mafiles_dir = if matches.occurrences_of("mafiles-path") > 0 {
|
||||||
matches.value_of("mafiles-path").unwrap().into()
|
matches.value_of("mafiles-path").unwrap().into()
|
||||||
|
|
Loading…
Reference in a new issue