converted some subcommands

This commit is contained in:
Carson McManus 2022-06-12 21:46:39 -04:00
parent 6ef038efc9
commit e6847975ff

View file

@ -1,5 +1,5 @@
extern crate rpassword; extern crate rpassword;
use clap::{crate_version, App, Arg, ArgMatches, Parser}; use clap::{crate_version, App, Arg, ArgMatches, Parser, Subcommand};
use log::*; use log::*;
use std::str::FromStr; use std::str::FromStr;
use std::{ use std::{
@ -45,7 +45,7 @@ struct Args {
verbosity: Verbosity, verbosity: Verbosity,
#[clap(subcommand)] #[clap(subcommand)]
sub: Subcommands, sub: Option<Subcommands>,
} }
#[derive(Debug, Clone, Parser)] #[derive(Debug, Clone, Parser)]
@ -67,7 +67,7 @@ enum Subcommands {
#[clap(about = "Set up a new account with steamguard-cli")] #[clap(about = "Set up a new account with steamguard-cli")]
Setup { Setup {
#[clap(short, long, from_global, help = "Steam username, case-sensitive.")] #[clap(short, long, from_global, help = "Steam username, case-sensitive.")]
username: String, username: Option<String>,
}, },
#[clap(about = "Import an account with steamguard already set up")] #[clap(about = "Import an account with steamguard already set up")]
Import { Import {
@ -238,7 +238,6 @@ fn main() {
fn run() -> anyhow::Result<()> { fn run() -> anyhow::Result<()> {
let new_args = Args::parse(); let new_args = Args::parse();
println!("{:?}", new_args); println!("{:?}", new_args);
return Ok(());
let matches = cli().get_matches(); let matches = cli().get_matches();
@ -249,19 +248,24 @@ fn run() -> anyhow::Result<()> {
.init() .init()
.unwrap(); .unwrap();
if let Some(demo_matches) = matches.subcommand_matches("debug") { if let Some(subcmd) = new_args.sub {
if demo_matches.is_present("demo-conf-menu") { match subcmd {
Subcommand::Debug{demo_conf_menu} => {
if demo_conf_menu {
demos::demo_confirmation_menu(); demos::demo_confirmation_menu();
} }
return Ok(()); return Ok(());
} },
if let Some(completion_matches) = matches.subcommand_matches("completion") { // Subcommand::Completions{shell} => {
// cli().gen_completions_to( // // cli().gen_completions_to(
// "steamguard", // // "steamguard",
// Shell::from_str(completion_matches.value_of("shell").unwrap()).unwrap(), // // Shell::from_str(completion_matches.value_of("shell").unwrap()).unwrap(),
// &mut std::io::stdout(), // // &mut std::io::stdout(),
// ); // // );
return Ok(()); // return Ok(());
// },
_ => {},
};
} }
let mafiles_dir = if matches.occurrences_of("mafiles-path") > 0 { let mafiles_dir = if matches.occurrences_of("mafiles-path") > 0 {
@ -323,6 +327,15 @@ fn run() -> anyhow::Result<()> {
} }
} }
if let Some(subcmd) = new_args.sub {
match subcmd {
Subcommands::Setup{ username } => {},
s => {
error!("Unknown subcommand: {:?}", s);
},
}
}
if matches.is_present("setup") { if matches.is_present("setup") {
println!("Log in to the account that you want to link to steamguard-cli"); println!("Log in to the account that you want to link to steamguard-cli");
print!("Username: "); print!("Username: ");
@ -505,6 +518,29 @@ fn run() -> anyhow::Result<()> {
.collect::<Vec<String>>() .collect::<Vec<String>>()
); );
if let Some(subcmd) = new_args.sub {
match subcmd {
Subcommands::Trade{ accept_all, fail_fast } => {
todo!()
},
s => {
error!("Unknown subcommand: {:?}", s);
},
}
} else {
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);
}
}
if let Some(trade_matches) = matches.subcommand_matches("trade") { if let Some(trade_matches) = matches.subcommand_matches("trade") {
info!("trade"); info!("trade");
for a in selected_accounts.iter_mut() { for a in selected_accounts.iter_mut() {
@ -640,18 +676,6 @@ fn run() -> anyhow::Result<()> {
} }
manifest.save()?; manifest.save()?;
} else {
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);
}
} }
Ok(()) Ok(())
} }
@ -776,3 +800,7 @@ fn get_mafiles_dir() -> String {
return paths[0].to_str().unwrap().into(); return paths[0].to_str().unwrap().into();
} }
fn do_subcmd_setup(args: Subcommands) -> anyhow::Result<()> {
}