add --offline flag for generating codes, closes #155
This commit is contained in:
parent
610cda120e
commit
fdc61e63d1
2 changed files with 37 additions and 3 deletions
26
src/cli.rs
26
src/cli.rs
|
@ -32,6 +32,12 @@ 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<Subcommands>,
|
||||
}
|
||||
|
@ -143,3 +149,23 @@ pub(crate) struct ArgsEncrypt;
|
|||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(about = "Decrypt all maFiles")]
|
||||
pub(crate) struct ArgsDecrypt;
|
||||
|
||||
#[derive(Debug, Clone, Parser)]
|
||||
#[clap(about = "Generate 2FA codes")]
|
||||
pub(crate) struct ArgsCode {
|
||||
#[clap(
|
||||
long,
|
||||
help = "Assume the computer's time is correct. Don't ask Steam for the time when generating codes."
|
||||
)]
|
||||
pub offline: bool,
|
||||
}
|
||||
|
||||
// HACK: the derive API doesn't support default subcommands, so we are going to make it so that it'll be easier to switch over when it's implemented.
|
||||
// See: https://github.com/clap-rs/clap/issues/3857
|
||||
impl From<Args> for ArgsCode {
|
||||
fn from(args: Args) -> Self {
|
||||
ArgsCode {
|
||||
offline: args.offline,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
src/main.rs
14
src/main.rs
|
@ -1,6 +1,7 @@
|
|||
extern crate rpassword;
|
||||
use clap::{IntoApp, Parser};
|
||||
use log::*;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::{
|
||||
io::{stdout, Write},
|
||||
path::Path,
|
||||
|
@ -180,7 +181,7 @@ fn run() -> anyhow::Result<()> {
|
|||
}
|
||||
_ => {
|
||||
debug!("No subcommand given, assuming user wants a 2fa code");
|
||||
return do_subcmd_code(selected_accounts);
|
||||
return do_subcmd_code(args.into(), selected_accounts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -662,8 +663,15 @@ fn do_subcmd_decrypt(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
fn do_subcmd_code(selected_accounts: Vec<Arc<Mutex<SteamGuardAccount>>>) -> anyhow::Result<()> {
|
||||
let server_time = steamapi::get_server_time()?.server_time;
|
||||
fn do_subcmd_code(
|
||||
args: cli::ArgsCode,
|
||||
selected_accounts: Vec<Arc<Mutex<SteamGuardAccount>>>,
|
||||
) -> anyhow::Result<()> {
|
||||
let server_time = if args.offline {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs()
|
||||
} else {
|
||||
steamapi::get_server_time()?.server_time
|
||||
};
|
||||
debug!("Time used to generate codes: {}", server_time);
|
||||
for account in selected_accounts {
|
||||
info!(
|
||||
|
|
Loading…
Reference in a new issue