From a52af3675b52d3994fface9cc18f5f4b378f7ff6 Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Tue, 21 Jun 2022 19:31:17 -0400 Subject: [PATCH] add code subcommand back in, because it makes the arg parsing better --- src/cli.rs | 14 +++++--------- src/main.rs | 15 +++++++-------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index 2931fd7..947f915 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -32,14 +32,11 @@ pub(crate) struct Args { #[clap(short, long, arg_enum, default_value_t=Verbosity::Info, help = "Set the log level. Be warned, trace is capable of printing sensitive data.")] pub verbosity: Verbosity, - #[clap( - long, - help = "Assume the computer's time is correct. Don't ask Steam for the time when generating codes." - )] - pub offline: bool, - #[clap(subcommand)] pub sub: Option, + + #[clap(flatten)] + pub code: ArgsCode, } #[derive(Debug, Clone, Parser)] @@ -52,6 +49,7 @@ pub(crate) enum Subcommands { Remove(ArgsRemove), Encrypt(ArgsEncrypt), Decrypt(ArgsDecrypt), + Code(ArgsCode), } #[derive(Debug, Clone, Copy, ArgEnum)] @@ -164,8 +162,6 @@ pub(crate) struct ArgsCode { // See: https://github.com/clap-rs/clap/issues/3857 impl From for ArgsCode { fn from(args: Args) -> Self { - ArgsCode { - offline: args.offline, - } + args.code } } diff --git a/src/main.rs b/src/main.rs index 80cdf47..60c7d89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -168,21 +168,20 @@ fn run() -> anyhow::Result<()> { .collect::>() ); - match args.sub { - Some(cli::Subcommands::Trade(args)) => { + match args.sub.unwrap_or(cli::Subcommands::Code(args.code)) { + cli::Subcommands::Trade(args) => { return do_subcmd_trade(args, &mut manifest, selected_accounts); } - Some(cli::Subcommands::Remove(args)) => { + cli::Subcommands::Remove(args) => { return do_subcmd_remove(args, &mut manifest, selected_accounts); } - Some(s) => { + cli::Subcommands::Code(args) => { + return do_subcmd_code(args, selected_accounts); + } + s => { error!("Unknown subcommand: {:?}", s); return Err(errors::UserError::UnknownSubcommand.into()); } - _ => { - debug!("No subcommand given, assuming user wants a 2fa code"); - return do_subcmd_code(args.into(), selected_accounts); - } } }