switch to a better setup for subcommands
This commit is contained in:
parent
2f4d1e3cfa
commit
07b9439c27
2 changed files with 54 additions and 71 deletions
93
src/cli.rs
93
src/cli.rs
|
@ -22,39 +22,16 @@ pub(crate) struct Args {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Parser)]
|
#[derive(Debug, Clone, Parser)]
|
||||||
pub(crate) enum Subcommands {
|
pub(crate) enum Subcommands {
|
||||||
Debug {
|
Debug(ArgsDebug),
|
||||||
#[clap(long)]
|
|
||||||
demo_conf_menu: bool
|
|
||||||
},
|
|
||||||
// Completions {
|
// Completions {
|
||||||
// TODO: Add completions
|
// TODO: Add completions
|
||||||
// },
|
// },
|
||||||
#[clap(about = "Interactive interface for trade confirmations")]
|
Setup(ArgsSetup),
|
||||||
Trade {
|
Import(ArgsImport),
|
||||||
#[clap(short, long, help = "Accept all open trade confirmations. Does not open interactive interface.")]
|
Trade(ArgsTrade),
|
||||||
accept_all: bool,
|
Remove(ArgsRemove),
|
||||||
#[clap(short, long, help = "If submitting a confirmation response fails, exit immediately.")]
|
Encrypt(ArgsEncrypt),
|
||||||
fail_fast: bool,
|
Decrypt(ArgsDecrypt),
|
||||||
},
|
|
||||||
#[clap(about = "Set up a new account with steamguard-cli")]
|
|
||||||
Setup {
|
|
||||||
#[clap(short, long, from_global, help = "Steam username, case-sensitive.")]
|
|
||||||
username: Option<String>,
|
|
||||||
},
|
|
||||||
#[clap(about = "Import an account with steamguard already set up")]
|
|
||||||
Import {
|
|
||||||
#[clap(long, help = "Paths to one or more maFiles, eg. \"./gaben.maFile\"")]
|
|
||||||
files: Vec<String>,
|
|
||||||
},
|
|
||||||
#[clap(about = "Remove the authenticator from an account.")]
|
|
||||||
Remove {
|
|
||||||
#[clap(short, long, from_global, help = "Steam username, case-sensitive.")]
|
|
||||||
username: String,
|
|
||||||
},
|
|
||||||
#[clap(about = "Encrypt all maFiles")]
|
|
||||||
Encrypt,
|
|
||||||
#[clap(about = "Decrypt all maFiles")]
|
|
||||||
Decrypt,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -93,42 +70,48 @@ impl FromStr for Verbosity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[clap(about="Debug stuff, not useful for most users.")]
|
||||||
|
pub(crate) struct ArgsDebug {
|
||||||
|
#[clap(long)]
|
||||||
|
pub demo_conf_menu: bool
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[clap(about = "Set up a new account with steamguard-cli")]
|
||||||
pub(crate) struct ArgsSetup {
|
pub(crate) struct ArgsSetup {
|
||||||
|
#[clap(short, long, from_global, help = "Steam username, case-sensitive.")]
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Subcommands> for ArgsSetup {
|
#[derive(Debug, Clone, Parser)]
|
||||||
fn from(sub: Subcommands) -> Self {
|
#[clap(about = "Import an account with steamguard already set up")]
|
||||||
match sub {
|
|
||||||
Subcommands::Setup { username } => Self { username },
|
|
||||||
_ => panic!("ArgsSetup::from() called with non-Setup subcommand"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct ArgsImport {
|
pub(crate) struct ArgsImport {
|
||||||
|
#[clap(long, help = "Paths to one or more maFiles, eg. \"./gaben.maFile\"")]
|
||||||
pub files: Vec<String>,
|
pub files: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Subcommands> for ArgsImport {
|
#[derive(Debug, Clone, Parser)]
|
||||||
fn from(sub: Subcommands) -> Self {
|
#[clap(about = "Interactive interface for trade confirmations")]
|
||||||
match sub {
|
|
||||||
Subcommands::Import { files } => Self { files },
|
|
||||||
_ => panic!("ArgsImport::from() called with non-Import subcommand"),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) struct ArgsTrade {
|
pub(crate) struct ArgsTrade {
|
||||||
|
#[clap(short, long, help = "Accept all open trade confirmations. Does not open interactive interface.")]
|
||||||
pub accept_all: bool,
|
pub accept_all: bool,
|
||||||
|
#[clap(short, long, help = "If submitting a confirmation response fails, exit immediately.")]
|
||||||
pub fail_fast: bool,
|
pub fail_fast: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<Subcommands> for ArgsTrade {
|
#[derive(Debug, Clone, Parser)]
|
||||||
fn from(sub: Subcommands) -> Self {
|
#[clap(about = "Remove the authenticator from an account.")]
|
||||||
match sub {
|
pub(crate) struct ArgsRemove {
|
||||||
Subcommands::Trade { accept_all, fail_fast } => Self { accept_all, fail_fast },
|
#[clap(short, long, from_global, help = "Steam username, case-sensitive.")]
|
||||||
_ => panic!("ArgsTrade::from() called with non-Trade subcommand"),
|
username: String,
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[clap(about = "Encrypt all maFiles")]
|
||||||
|
pub(crate) struct ArgsEncrypt;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
#[clap(about = "Decrypt all maFiles")]
|
||||||
|
pub(crate) struct ArgsDecrypt;
|
||||||
|
|
30
src/main.rs
30
src/main.rs
|
@ -11,7 +11,7 @@ use steamguard::{
|
||||||
SteamGuardAccount, UserLogin,
|
SteamGuardAccount, UserLogin,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::accountmanager::ManifestAccountLoadError;
|
use crate::{accountmanager::ManifestAccountLoadError, cli::Subcommands};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
@ -157,8 +157,8 @@ fn run() -> anyhow::Result<()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match new_args.sub {
|
match new_args.sub {
|
||||||
Some(cli::Subcommands::Debug{demo_conf_menu}) => {
|
Some(cli::Subcommands::Debug(args)) => {
|
||||||
if demo_conf_menu {
|
if args.demo_conf_menu {
|
||||||
demos::demo_confirmation_menu();
|
demos::demo_confirmation_menu();
|
||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
@ -233,13 +233,13 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match &new_args.sub {
|
match new_args.sub {
|
||||||
Some(cli::Subcommands::Setup{ username }) => {
|
Some(cli::Subcommands::Setup(args)) => {
|
||||||
return do_subcmd_setup(new_args.sub.unwrap().into(), &mut manifest);
|
return do_subcmd_setup(args, &mut manifest);
|
||||||
},
|
},
|
||||||
Some(cli::Subcommands::Import { files }) => {todo!()},
|
Some(cli::Subcommands::Import(args)) => {todo!()},
|
||||||
Some(cli::Subcommands::Encrypt {}) => {todo!()},
|
Some(cli::Subcommands::Encrypt(args)) => {todo!()},
|
||||||
Some(cli::Subcommands::Decrypt {}) => {todo!()},
|
Some(cli::Subcommands::Decrypt(args)) => {todo!()},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,7 +321,7 @@ fn run() -> anyhow::Result<()> {
|
||||||
);
|
);
|
||||||
|
|
||||||
match new_args.sub.as_ref() {
|
match new_args.sub.as_ref() {
|
||||||
Some(cli::Subcommands::Trade{ accept_all, fail_fast }) => {
|
Some(cli::Subcommands::Trade(args)) => {
|
||||||
for a in selected_accounts.iter_mut() {
|
for a in selected_accounts.iter_mut() {
|
||||||
let mut account = a.lock().unwrap();
|
let mut account = a.lock().unwrap();
|
||||||
|
|
||||||
|
@ -341,14 +341,14 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut any_failed = false;
|
let mut any_failed = false;
|
||||||
if *accept_all {
|
if args.accept_all {
|
||||||
info!("accepting all confirmations");
|
info!("accepting all confirmations");
|
||||||
for conf in &confirmations {
|
for conf in &confirmations {
|
||||||
let result = account.accept_confirmation(conf);
|
let result = account.accept_confirmation(conf);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
warn!("accept confirmation result: {:?}", result);
|
warn!("accept confirmation result: {:?}", result);
|
||||||
any_failed = true;
|
any_failed = true;
|
||||||
if *fail_fast {
|
if args.fail_fast {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -363,7 +363,7 @@ fn run() -> anyhow::Result<()> {
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
warn!("accept confirmation result: {:?}", result);
|
warn!("accept confirmation result: {:?}", result);
|
||||||
any_failed = true;
|
any_failed = true;
|
||||||
if *fail_fast {
|
if args.fail_fast {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -376,7 +376,7 @@ fn run() -> anyhow::Result<()> {
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
warn!("deny confirmation result: {:?}", result);
|
warn!("deny confirmation result: {:?}", result);
|
||||||
any_failed = true;
|
any_failed = true;
|
||||||
if *fail_fast {
|
if args.fail_fast {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -398,7 +398,7 @@ fn run() -> anyhow::Result<()> {
|
||||||
|
|
||||||
manifest.save()?;
|
manifest.save()?;
|
||||||
},
|
},
|
||||||
Some(cli::Subcommands::Remove { username }) => {
|
Some(cli::Subcommands::Remove(args)) => {
|
||||||
println!(
|
println!(
|
||||||
"This will remove the mobile authenticator from {} accounts: {}",
|
"This will remove the mobile authenticator from {} accounts: {}",
|
||||||
selected_accounts.len(),
|
selected_accounts.len(),
|
||||||
|
|
Loading…
Reference in a new issue