From 23257ee615959548d268098ebebdc8a32800d80c Mon Sep 17 00:00:00 2001 From: Carson McManus Date: Sat, 27 Mar 2021 12:14:34 -0400 Subject: [PATCH] add account selection from arguments --- src/lib.rs | 2 +- src/main.rs | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index e526566..5639dcb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ mod steamapi; extern crate hmacsha1; extern crate base64; -#[derive(Debug, Serialize, Deserialize)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct SteamGuardAccount { pub account_name: String, pub serial_number: String, diff --git a/src/main.rs b/src/main.rs index ec703d5..b8cafee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate rpassword; +use borrow::BorrowMut; use io::Write; use steamguard_cli::*; use ::std::*; @@ -26,6 +27,7 @@ fn main() { Arg::with_name("all") .long("all") .short("a") + .takes_value(false) .help("Select all accounts in the manifest.") ) .arg( @@ -55,6 +57,7 @@ fn main() { Arg::with_name("accept-all") .short("a") .long("accept-all") + .takes_value(false) .help("Accept all open trade confirmations. Does not open interactive interface.") ) ) @@ -79,9 +82,30 @@ fn main() { } manifest.load_accounts(); - for account in manifest.accounts { + let mut selected_accounts: Vec = vec![]; + if matches.is_present("all") { + // manifest.accounts.iter().map(|a| selected_accounts.push(a.b)); + for account in manifest.accounts { + selected_accounts.push(account.clone()); + } + } else { + for account in manifest.accounts { + if !matches.is_present("username") { + selected_accounts.push(account.clone()); + break; + } + if matches.value_of("username").unwrap() == account.account_name { + selected_accounts.push(account.clone()); + break; + } + } + } + + debug!("selected accounts: {:?}", selected_accounts.iter().map(|a| a.account_name.clone()).collect::>()); + + let server_time = steamapi::get_server_time(); + for account in selected_accounts { trace!("{:?}", account); - let server_time = steamapi::get_server_time(); let code = account.generate_code(server_time); println!("{}", code); }