2022-06-19 16:48:18 +02:00
use std ::str ::FromStr ;
use clap ::Parser ;
#[ derive(Debug, Clone, Parser) ]
#[ clap(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, 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 < String > ,
#[ clap(short, long, help = " Select all accounts in the manifest. " ) ]
pub all : bool ,
/// The path to the maFiles directory.
2022-06-19 17:26:18 +02:00
#[ 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 < String > ,
2022-06-19 16:48:18 +02:00
#[ clap(short, long, help = " Specify your encryption passkey. " ) ]
pub passkey : Option < String > ,
#[ clap(short, long, default_value_t=Verbosity::Info, help = " Set the log level. " ) ]
pub verbosity : Verbosity ,
#[ clap(subcommand) ]
pub sub : Option < Subcommands > ,
}
#[ derive(Debug, Clone, Parser) ]
pub ( crate ) enum Subcommands {
2022-06-19 17:14:35 +02:00
Debug ( ArgsDebug ) ,
2022-06-19 16:48:18 +02:00
// Completions {
// TODO: Add completions
// },
2022-06-19 17:14:35 +02:00
Setup ( ArgsSetup ) ,
Import ( ArgsImport ) ,
Trade ( ArgsTrade ) ,
Remove ( ArgsRemove ) ,
Encrypt ( ArgsEncrypt ) ,
Decrypt ( ArgsDecrypt ) ,
2022-06-19 16:48:18 +02:00
}
#[ derive(Debug, Clone, Copy) ]
pub ( crate ) enum Verbosity {
Error = 0 ,
Warn = 1 ,
Info = 2 ,
Debug = 3 ,
Trace = 4 ,
}
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 " ,
} ) )
}
}
impl FromStr for Verbosity {
type Err = anyhow ::Error ;
fn from_str ( s : & str ) -> Result < Self , Self ::Err > {
match s {
" error " = > Ok ( Verbosity ::Error ) ,
" warn " = > Ok ( Verbosity ::Warn ) ,
" info " = > Ok ( Verbosity ::Info ) ,
" debug " = > Ok ( Verbosity ::Debug ) ,
" trace " = > Ok ( Verbosity ::Trace ) ,
_ = > Err ( anyhow! ( " Invalid verbosity level: {} " , s ) ) ,
}
}
}
2022-06-19 17:14:35 +02:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about= " Debug stuff, not useful for most users. " ) ]
pub ( crate ) struct ArgsDebug {
#[ clap(long) ]
pub demo_conf_menu : bool
2022-06-19 16:48:18 +02:00
}
2022-06-19 17:14:35 +02:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Set up a new account with steamguard-cli " ) ]
pub ( crate ) struct ArgsSetup {
#[ clap(short, long, from_global, help = " Steam username, case-sensitive. " ) ]
pub username : Option < String > ,
2022-06-19 16:48:18 +02:00
}
2022-06-19 17:14:35 +02:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Import an account with steamguard already set up " ) ]
2022-06-19 16:48:18 +02:00
pub ( crate ) struct ArgsImport {
2022-06-19 17:14:35 +02:00
#[ clap(long, help = " Paths to one or more maFiles, eg. \" ./gaben.maFile \" " ) ]
2022-06-19 16:48:18 +02:00
pub files : Vec < String > ,
}
2022-06-19 17:14:35 +02:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Interactive interface for trade confirmations " ) ]
2022-06-19 16:48:18 +02:00
pub ( crate ) struct ArgsTrade {
2022-06-19 17:14:35 +02:00
#[ clap(short, long, help = " Accept all open trade confirmations. Does not open interactive interface. " ) ]
2022-06-19 16:48:18 +02:00
pub accept_all : bool ,
2022-06-19 17:14:35 +02:00
#[ clap(short, long, help = " If submitting a confirmation response fails, exit immediately. " ) ]
2022-06-19 16:48:18 +02:00
pub fail_fast : bool ,
}
2022-06-19 17:14:35 +02:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Remove the authenticator from an account. " ) ]
pub ( crate ) struct ArgsRemove {
#[ clap(short, long, from_global, help = " Steam username, case-sensitive. " ) ]
username : String ,
}
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Encrypt all maFiles " ) ]
pub ( crate ) struct ArgsEncrypt ;
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Decrypt all maFiles " ) ]
pub ( crate ) struct ArgsDecrypt ;