make it compile again
This commit is contained in:
parent
14d49d33b1
commit
2f4d1e3cfa
1 changed files with 130 additions and 129 deletions
259
src/main.rs
259
src/main.rs
|
@ -233,9 +233,9 @@ fn run() -> anyhow::Result<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match new_args.sub {
|
match &new_args.sub {
|
||||||
Some(cli::Subcommands::Setup{ username }) => {
|
Some(cli::Subcommands::Setup{ username }) => {
|
||||||
do_subcmd_setup(new_args.sub.unwrap().into(), &mut manifest)?;
|
return do_subcmd_setup(new_args.sub.unwrap().into(), &mut manifest);
|
||||||
},
|
},
|
||||||
Some(cli::Subcommands::Import { files }) => {todo!()},
|
Some(cli::Subcommands::Import { files }) => {todo!()},
|
||||||
Some(cli::Subcommands::Encrypt {}) => {todo!()},
|
Some(cli::Subcommands::Encrypt {}) => {todo!()},
|
||||||
|
@ -320,158 +320,159 @@ fn run() -> anyhow::Result<()> {
|
||||||
.collect::<Vec<String>>()
|
.collect::<Vec<String>>()
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(subcmd) = new_args.sub {
|
match new_args.sub.as_ref() {
|
||||||
match subcmd {
|
Some(cli::Subcommands::Trade{ accept_all, fail_fast }) => {
|
||||||
cli::Subcommands::Trade{ accept_all, fail_fast } => {
|
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();
|
|
||||||
|
|
||||||
info!("Checking for trade confirmations");
|
info!("Checking for trade confirmations");
|
||||||
let confirmations: Vec<Confirmation>;
|
let confirmations: Vec<Confirmation>;
|
||||||
loop {
|
loop {
|
||||||
match account.get_trade_confirmations() {
|
match account.get_trade_confirmations() {
|
||||||
Ok(confs) => {
|
Ok(confs) => {
|
||||||
confirmations = confs;
|
confirmations = confs;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
info!("failed to get trade confirmations, asking user to log in");
|
info!("failed to get trade confirmations, asking user to log in");
|
||||||
do_login(&mut account)?;
|
do_login(&mut account)?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let mut any_failed = false;
|
let mut any_failed = false;
|
||||||
if accept_all {
|
if *accept_all {
|
||||||
info!("accepting all confirmations");
|
info!("accepting all confirmations");
|
||||||
for conf in &confirmations {
|
for conf in &confirmations {
|
||||||
|
let result = account.accept_confirmation(conf);
|
||||||
|
if result.is_err() {
|
||||||
|
warn!("accept confirmation result: {:?}", result);
|
||||||
|
any_failed = true;
|
||||||
|
if *fail_fast {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("accept confirmation result: {:?}", result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if termion::is_tty(&stdout()) {
|
||||||
|
let (accept, deny) = tui::prompt_confirmation_menu(confirmations);
|
||||||
|
for conf in &accept {
|
||||||
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 *fail_fast {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!("accept confirmation result: {:?}", result);
|
debug!("accept confirmation result: {:?}", result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
for conf in &deny {
|
||||||
if termion::is_tty(&stdout()) {
|
let result = account.deny_confirmation(conf);
|
||||||
let (accept, deny) = tui::prompt_confirmation_menu(confirmations);
|
debug!("deny confirmation result: {:?}", result);
|
||||||
for conf in &accept {
|
if result.is_err() {
|
||||||
let result = account.accept_confirmation(conf);
|
warn!("deny confirmation result: {:?}", result);
|
||||||
if result.is_err() {
|
any_failed = true;
|
||||||
warn!("accept confirmation result: {:?}", result);
|
if *fail_fast {
|
||||||
any_failed = true;
|
return result;
|
||||||
if fail_fast {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!("accept confirmation result: {:?}", result);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for conf in &deny {
|
|
||||||
let result = account.deny_confirmation(conf);
|
|
||||||
debug!("deny confirmation result: {:?}", result);
|
|
||||||
if result.is_err() {
|
|
||||||
warn!("deny confirmation result: {:?}", result);
|
|
||||||
any_failed = true;
|
|
||||||
if fail_fast {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!("deny confirmation result: {:?}", result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
warn!("not a tty, not showing menu");
|
|
||||||
for conf in &confirmations {
|
|
||||||
println!("{}", conf.description());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if any_failed {
|
|
||||||
error!("Failed to respond to some confirmations.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
manifest.save()?;
|
|
||||||
},
|
|
||||||
cli::Subcommands::Remove { username } => {
|
|
||||||
println!(
|
|
||||||
"This will remove the mobile authenticator from {} accounts: {}",
|
|
||||||
selected_accounts.len(),
|
|
||||||
selected_accounts
|
|
||||||
.iter()
|
|
||||||
.map(|a| a.lock().unwrap().account_name.clone())
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(", ")
|
|
||||||
);
|
|
||||||
|
|
||||||
match tui::prompt_char("Do you want to continue?", "yN") {
|
|
||||||
'y' => {}
|
|
||||||
_ => {
|
|
||||||
info!("Aborting!");
|
|
||||||
return Err(errors::UserError::Aborted.into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut successful = vec![];
|
|
||||||
for a in selected_accounts {
|
|
||||||
let account = a.lock().unwrap();
|
|
||||||
match account.remove_authenticator(None) {
|
|
||||||
Ok(success) => {
|
|
||||||
if success {
|
|
||||||
println!("Removed authenticator from {}", account.account_name);
|
|
||||||
successful.push(account.account_name.clone());
|
|
||||||
} else {
|
} else {
|
||||||
println!(
|
debug!("deny confirmation result: {:?}", result);
|
||||||
"Failed to remove authenticator from {}",
|
|
||||||
account.account_name
|
|
||||||
);
|
|
||||||
match tui::prompt_char(
|
|
||||||
"Would you like to remove it from the manifest anyway?",
|
|
||||||
"yN",
|
|
||||||
) {
|
|
||||||
'y' => {
|
|
||||||
successful.push(account.account_name.clone());
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(err) => {
|
} else {
|
||||||
error!(
|
warn!("not a tty, not showing menu");
|
||||||
"Unexpected error when removing authenticator from {}: {}",
|
for conf in &confirmations {
|
||||||
account.account_name, err
|
println!("{}", conf.description());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for account_name in successful {
|
if any_failed {
|
||||||
manifest.remove_account(account_name);
|
error!("Failed to respond to some confirmations.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
manifest.save()?;
|
manifest.save()?;
|
||||||
},
|
},
|
||||||
s => {
|
Some(cli::Subcommands::Remove { username }) => {
|
||||||
error!("Unknown subcommand: {:?}", s);
|
println!(
|
||||||
},
|
"This will remove the mobile authenticator from {} accounts: {}",
|
||||||
}
|
selected_accounts.len(),
|
||||||
} else {
|
selected_accounts
|
||||||
let server_time = steamapi::get_server_time();
|
.iter()
|
||||||
debug!("Time used to generate codes: {}", server_time);
|
.map(|a| a.lock().unwrap().account_name.clone())
|
||||||
for account in selected_accounts {
|
.collect::<Vec<String>>()
|
||||||
info!(
|
.join(", ")
|
||||||
"Generating code for {}",
|
|
||||||
account.lock().unwrap().account_name
|
|
||||||
);
|
);
|
||||||
trace!("{:?}", account);
|
|
||||||
let code = account.lock().unwrap().generate_code(server_time);
|
match tui::prompt_char("Do you want to continue?", "yN") {
|
||||||
println!("{}", code);
|
'y' => {}
|
||||||
|
_ => {
|
||||||
|
info!("Aborting!");
|
||||||
|
return Err(errors::UserError::Aborted.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut successful = vec![];
|
||||||
|
for a in selected_accounts {
|
||||||
|
let account = a.lock().unwrap();
|
||||||
|
match account.remove_authenticator(None) {
|
||||||
|
Ok(success) => {
|
||||||
|
if success {
|
||||||
|
println!("Removed authenticator from {}", account.account_name);
|
||||||
|
successful.push(account.account_name.clone());
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"Failed to remove authenticator from {}",
|
||||||
|
account.account_name
|
||||||
|
);
|
||||||
|
match tui::prompt_char(
|
||||||
|
"Would you like to remove it from the manifest anyway?",
|
||||||
|
"yN",
|
||||||
|
) {
|
||||||
|
'y' => {
|
||||||
|
successful.push(account.account_name.clone());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
error!(
|
||||||
|
"Unexpected error when removing authenticator from {}: {}",
|
||||||
|
account.account_name, err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for account_name in successful {
|
||||||
|
manifest.remove_account(account_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
manifest.save()?;
|
||||||
|
},
|
||||||
|
Some(s) => {
|
||||||
|
error!("Unknown subcommand: {:?}", s);
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
debug!("No subcommand given, assuming user wants a 2fa code");
|
||||||
|
|
||||||
|
let server_time = steamapi::get_server_time();
|
||||||
|
debug!("Time used to generate codes: {}", server_time);
|
||||||
|
for account in selected_accounts {
|
||||||
|
info!(
|
||||||
|
"Generating code for {}",
|
||||||
|
account.lock().unwrap().account_name
|
||||||
|
);
|
||||||
|
trace!("{:?}", account);
|
||||||
|
let code = account.lock().unwrap().generate_code(server_time);
|
||||||
|
println!("{}", code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue