diff --git a/src/cli.rs b/src/cli.rs index 8bd251b..687d904 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,16 +1,31 @@ -use std::str::FromStr; -use clap::{Parser, clap_derive::ArgEnum}; +use clap::{clap_derive::ArgEnum, Parser}; use clap_complete::Shell; +use std::str::FromStr; #[derive(Debug, Clone, Parser)] #[clap(name="steamguard-cli", bin_name="steamguard", author, version, about = "Generate Steam 2FA codes and confirm Steam trades from the command line.", long_about = None)] pub(crate) struct Args { - #[clap(short, long, conflicts_with="all", help = "Steam username, case-sensitive.", long_help = "Select the account you want by steam username. Case-sensitive. By default, the first account in the manifest is selected.")] + #[clap( + short, + long, + conflicts_with = "all", + help = "Steam username, case-sensitive.", + long_help = "Select the account you want by steam username. Case-sensitive. By default, the first account in the manifest is selected." + )] pub username: Option, - #[clap(short, long, conflicts_with="username", help = "Select all accounts in the manifest.")] + #[clap( + short, + long, + conflicts_with = "username", + help = "Select all accounts in the manifest." + )] pub all: bool, /// The path to the maFiles directory. - #[clap(short, long, help = "Specify which folder your maFiles are in. This should be a path to a folder that contains manifest.json. Default: ~/.config/steamguard-cli/maFiles")] + #[clap( + short, + long, + help = "Specify which folder your maFiles are in. This should be a path to a folder that contains manifest.json. Default: ~/.config/steamguard-cli/maFiles" + )] pub mafiles_path: Option, #[clap(short, long, help = "Specify your encryption passkey.")] pub passkey: Option, @@ -44,13 +59,16 @@ pub(crate) enum Verbosity { impl std::fmt::Display for Verbosity { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_fmt(format_args!("{}", match self { - Verbosity::Error => "error", - Verbosity::Warn => "warn", - Verbosity::Info => "info", - Verbosity::Debug => "debug", - Verbosity::Trace => "trace", - })) + f.write_fmt(format_args!( + "{}", + match self { + Verbosity::Error => "error", + Verbosity::Warn => "warn", + Verbosity::Info => "info", + Verbosity::Debug => "debug", + Verbosity::Trace => "trace", + } + )) } } @@ -69,16 +87,15 @@ impl FromStr for Verbosity { } } - #[derive(Debug, Clone, Parser)] -#[clap(about="Debug stuff, not useful for most users.")] +#[clap(about = "Debug stuff, not useful for most users.")] pub(crate) struct ArgsDebug { #[clap(long, help = "Show an example confirmation menu using dummy data.")] - pub demo_conf_menu: bool + pub demo_conf_menu: bool, } #[derive(Debug, Clone, Parser)] -#[clap(about="Generate shell completions")] +#[clap(about = "Generate shell completions")] pub(crate) struct ArgsCompletions { #[clap(short, long, arg_enum, help = "The shell to generate completions for.")] pub shell: Shell, @@ -101,9 +118,17 @@ pub(crate) struct ArgsImport { #[derive(Debug, Clone, Parser)] #[clap(about = "Interactive interface for trade confirmations")] pub(crate) struct ArgsTrade { - #[clap(short, long, help = "Accept all open trade confirmations. Does not open interactive interface.")] + #[clap( + short, + long, + help = "Accept all open trade confirmations. Does not open interactive interface." + )] pub accept_all: bool, - #[clap(short, long, help = "If submitting a confirmation response fails, exit immediately.")] + #[clap( + short, + long, + help = "If submitting a confirmation response fails, exit immediately." + )] pub fail_fast: bool, } diff --git a/src/main.rs b/src/main.rs index 07b5ff5..d65f3d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ extern crate rpassword; -use clap::{Parser, IntoApp}; +use clap::{IntoApp, Parser}; use log::*; use std::{ io::{stdout, Write}, @@ -53,11 +53,11 @@ fn run() -> anyhow::Result<()> { match args.sub { Some(cli::Subcommands::Debug(args)) => { return do_subcmd_debug(args); - }, + } Some(cli::Subcommands::Completion(args)) => { return do_subcmd_completion(args); - }, - _ => {}, + } + _ => {} }; let mafiles_dir = if let Some(mafiles_path) = &args.mafiles_path { @@ -122,17 +122,17 @@ fn run() -> anyhow::Result<()> { match args.sub { Some(cli::Subcommands::Setup(args)) => { return do_subcmd_setup(args, &mut manifest); - }, + } Some(cli::Subcommands::Import(args)) => { return do_subcmd_import(args, &mut manifest); - }, + } Some(cli::Subcommands::Encrypt(args)) => { return do_subcmd_encrypt(args, &mut manifest); - }, + } Some(cli::Subcommands::Decrypt(args)) => { return do_subcmd_decrypt(args, &mut manifest); - }, - _ => {}, + } + _ => {} } let selected_accounts: Vec>>; @@ -170,14 +170,14 @@ fn run() -> anyhow::Result<()> { match args.sub { Some(cli::Subcommands::Trade(args)) => { return do_subcmd_trade(args, &mut manifest, selected_accounts); - }, + } Some(cli::Subcommands::Remove(args)) => { return do_subcmd_remove(args, &mut manifest, selected_accounts); - }, + } Some(s) => { error!("Unknown subcommand: {:?}", s); return Err(errors::UserError::UnknownSubcommand.into()); - }, + } _ => { debug!("No subcommand given, assuming user wants a 2fa code"); return do_subcmd_code(selected_accounts); @@ -319,7 +319,10 @@ fn do_subcmd_completion(args: cli::ArgsCompletions) -> Result<(), anyhow::Error> return Ok(()); } -fn do_subcmd_setup(args: cli::ArgsSetup, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> { +fn do_subcmd_setup( + args: cli::ArgsSetup, + manifest: &mut accountmanager::Manifest, +) -> anyhow::Result<()> { println!("Log in to the account that you want to link to steamguard-cli"); print!("Username: "); let username = if args.username.is_some() { @@ -336,8 +339,7 @@ fn do_subcmd_setup(args: cli::ArgsSetup, manifest: &mut accountmanager::Manifest username ); } - let session = - do_login_raw(username).expect("Failed to log in. Account has not been linked."); + let session = do_login_raw(username).expect("Failed to log in. Account has not been linked."); let mut linker = AccountLinker::new(session); let account: SteamGuardAccount; @@ -434,7 +436,10 @@ fn do_subcmd_setup(args: cli::ArgsSetup, manifest: &mut accountmanager::Manifest return Ok(()); } -fn do_subcmd_import(args: cli::ArgsImport, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> { +fn do_subcmd_import( + args: cli::ArgsImport, + manifest: &mut accountmanager::Manifest, +) -> anyhow::Result<()> { for file_path in args.files { match manifest.import_account(&file_path) { Ok(_) => { @@ -450,7 +455,11 @@ fn do_subcmd_import(args: cli::ArgsImport, manifest: &mut accountmanager::Manife return Ok(()); } -fn do_subcmd_trade(args: cli::ArgsTrade, manifest: &mut accountmanager::Manifest, mut selected_accounts: Vec>>) -> anyhow::Result<()> { +fn do_subcmd_trade( + args: cli::ArgsTrade, + manifest: &mut accountmanager::Manifest, + mut selected_accounts: Vec>>, +) -> anyhow::Result<()> { for a in selected_accounts.iter_mut() { let mut account = a.lock().unwrap(); @@ -529,7 +538,11 @@ fn do_subcmd_trade(args: cli::ArgsTrade, manifest: &mut accountmanager::Manifest return Ok(()); } -fn do_subcmd_remove(_args: cli::ArgsRemove, manifest: &mut accountmanager::Manifest, selected_accounts: Vec>>) -> anyhow::Result<()> { +fn do_subcmd_remove( + _args: cli::ArgsRemove, + manifest: &mut accountmanager::Manifest, + selected_accounts: Vec>>, +) -> anyhow::Result<()> { println!( "This will remove the mobile authenticator from {} accounts: {}", selected_accounts.len(), @@ -589,7 +602,10 @@ fn do_subcmd_remove(_args: cli::ArgsRemove, manifest: &mut accountmanager::Manif return Ok(()); } -fn do_subcmd_encrypt(_args: cli::ArgsEncrypt, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> { +fn do_subcmd_encrypt( + _args: cli::ArgsEncrypt, + manifest: &mut accountmanager::Manifest, +) -> anyhow::Result<()> { if !manifest.has_passkey() { let mut passkey; loop { @@ -611,7 +627,10 @@ fn do_subcmd_encrypt(_args: cli::ArgsEncrypt, manifest: &mut accountmanager::Man return Ok(()); } -fn do_subcmd_decrypt(_args: cli::ArgsDecrypt, manifest: &mut accountmanager::Manifest) -> anyhow::Result<()> { +fn do_subcmd_decrypt( + _args: cli::ArgsDecrypt, + manifest: &mut accountmanager::Manifest, +) -> anyhow::Result<()> { manifest.load_accounts()?; for entry in &mut manifest.entries { entry.encryption = None;