add code subcommand back in, because it makes the arg parsing better
This commit is contained in:
parent
fdc61e63d1
commit
a52af3675b
2 changed files with 12 additions and 17 deletions
14
src/cli.rs
14
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.")]
|
#[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,
|
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)]
|
#[clap(subcommand)]
|
||||||
pub sub: Option<Subcommands>,
|
pub sub: Option<Subcommands>,
|
||||||
|
|
||||||
|
#[clap(flatten)]
|
||||||
|
pub code: ArgsCode,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Parser)]
|
#[derive(Debug, Clone, Parser)]
|
||||||
|
@ -52,6 +49,7 @@ pub(crate) enum Subcommands {
|
||||||
Remove(ArgsRemove),
|
Remove(ArgsRemove),
|
||||||
Encrypt(ArgsEncrypt),
|
Encrypt(ArgsEncrypt),
|
||||||
Decrypt(ArgsDecrypt),
|
Decrypt(ArgsDecrypt),
|
||||||
|
Code(ArgsCode),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, ArgEnum)]
|
#[derive(Debug, Clone, Copy, ArgEnum)]
|
||||||
|
@ -164,8 +162,6 @@ pub(crate) struct ArgsCode {
|
||||||
// See: https://github.com/clap-rs/clap/issues/3857
|
// See: https://github.com/clap-rs/clap/issues/3857
|
||||||
impl From<Args> for ArgsCode {
|
impl From<Args> for ArgsCode {
|
||||||
fn from(args: Args) -> Self {
|
fn from(args: Args) -> Self {
|
||||||
ArgsCode {
|
args.code
|
||||||
offline: args.offline,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -168,21 +168,20 @@ fn run() -> anyhow::Result<()> {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
);
|
);
|
||||||
|
|
||||||
match args.sub {
|
match args.sub.unwrap_or(cli::Subcommands::Code(args.code)) {
|
||||||
Some(cli::Subcommands::Trade(args)) => {
|
cli::Subcommands::Trade(args) => {
|
||||||
return do_subcmd_trade(args, &mut manifest, selected_accounts);
|
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);
|
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);
|
error!("Unknown subcommand: {:?}", s);
|
||||||
return Err(errors::UserError::UnknownSubcommand.into());
|
return Err(errors::UserError::UnknownSubcommand.into());
|
||||||
}
|
}
|
||||||
_ => {
|
|
||||||
debug!("No subcommand given, assuming user wants a 2fa code");
|
|
||||||
return do_subcmd_code(args.into(), selected_accounts);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue