2022-06-19 14:44:47 -04:00
use clap ::{ clap_derive ::ArgEnum , Parser } ;
2022-06-19 12:37:40 -04:00
use clap_complete ::Shell ;
2022-06-19 14:44:47 -04:00
use std ::str ::FromStr ;
2022-06-19 10:48:18 -04:00
#[ derive(Debug, Clone, Parser) ]
2022-06-19 12:42:36 -04:00
#[ 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) ]
2022-06-19 10:48:18 -04:00
pub ( crate ) struct Args {
2022-06-19 14:44:47 -04:00
#[ 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. "
) ]
2022-06-19 10:48:18 -04:00
pub username : Option < String > ,
2022-06-19 14:44:47 -04:00
#[ clap(
short ,
long ,
conflicts_with = " username " ,
help = " Select all accounts in the manifest. "
) ]
2022-06-19 10:48:18 -04:00
pub all : bool ,
/// The path to the maFiles directory.
2022-06-19 14:44:47 -04: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 "
) ]
2022-06-19 11:26:18 -04:00
pub mafiles_path : Option < String > ,
2022-06-23 23:29:14 -04:00
#[ clap(
short ,
long ,
env = " STEAMGUARD_CLI_PASSKEY " ,
help = " Specify your encryption passkey. "
) ]
2022-06-19 10:48:18 -04:00
pub passkey : Option < String > ,
2022-06-19 12:48:07 -04:00
#[ clap(short, long, arg_enum, default_value_t=Verbosity::Info, help = " Set the log level. Be warned, trace is capable of printing sensitive data. " ) ]
2022-06-19 10:48:18 -04:00
pub verbosity : Verbosity ,
#[ clap(subcommand) ]
pub sub : Option < Subcommands > ,
2022-06-21 19:31:17 -04:00
#[ clap(flatten) ]
pub code : ArgsCode ,
2022-06-19 10:48:18 -04:00
}
#[ derive(Debug, Clone, Parser) ]
pub ( crate ) enum Subcommands {
2022-06-19 11:14:35 -04:00
Debug ( ArgsDebug ) ,
2022-06-19 12:37:40 -04:00
Completion ( ArgsCompletions ) ,
2022-06-19 11:14:35 -04:00
Setup ( ArgsSetup ) ,
Import ( ArgsImport ) ,
Trade ( ArgsTrade ) ,
Remove ( ArgsRemove ) ,
Encrypt ( ArgsEncrypt ) ,
Decrypt ( ArgsDecrypt ) ,
2022-06-21 19:31:17 -04:00
Code ( ArgsCode ) ,
2022-06-19 10:48:18 -04:00
}
2022-06-19 12:47:07 -04:00
#[ derive(Debug, Clone, Copy, ArgEnum) ]
2022-06-19 10:48:18 -04:00
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 {
2022-06-19 14:44:47 -04:00
f . write_fmt ( format_args! (
" {} " ,
match self {
Verbosity ::Error = > " error " ,
Verbosity ::Warn = > " warn " ,
Verbosity ::Info = > " info " ,
Verbosity ::Debug = > " debug " ,
Verbosity ::Trace = > " trace " ,
}
) )
2022-06-19 10:48:18 -04:00
}
}
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 11:14:35 -04:00
#[ derive(Debug, Clone, Parser) ]
2022-06-19 14:44:47 -04:00
#[ clap(about = " Debug stuff, not useful for most users. " ) ]
2022-06-19 11:14:35 -04:00
pub ( crate ) struct ArgsDebug {
2022-06-25 10:57:37 -04:00
#[ clap(long, help = " Show a text prompt. " ) ]
pub demo_prompt : bool ,
#[ clap(long, help = " Show a character prompt. " ) ]
pub demo_prompt_char : bool ,
2022-06-19 11:32:04 -04:00
#[ clap(long, help = " Show an example confirmation menu using dummy data. " ) ]
2022-06-19 14:44:47 -04:00
pub demo_conf_menu : bool ,
2022-06-19 10:48:18 -04:00
}
2022-06-19 12:37:40 -04:00
#[ derive(Debug, Clone, Parser) ]
2022-06-19 14:44:47 -04:00
#[ clap(about = " Generate shell completions " ) ]
2022-06-19 12:37:40 -04:00
pub ( crate ) struct ArgsCompletions {
2022-06-19 12:39:33 -04:00
#[ clap(short, long, arg_enum, help = " The shell to generate completions for. " ) ]
2022-06-19 12:37:40 -04:00
pub shell : Shell ,
}
2022-06-19 11:14:35 -04: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 10:48:18 -04:00
}
2022-06-19 11:14:35 -04:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Import an account with steamguard already set up " ) ]
2022-06-19 10:48:18 -04:00
pub ( crate ) struct ArgsImport {
2022-06-19 11:14:35 -04:00
#[ clap(long, help = " Paths to one or more maFiles, eg. \" ./gaben.maFile \" " ) ]
2022-06-19 10:48:18 -04:00
pub files : Vec < String > ,
}
2022-06-19 11:14:35 -04:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Interactive interface for trade confirmations " ) ]
2022-06-19 10:48:18 -04:00
pub ( crate ) struct ArgsTrade {
2022-06-19 14:44:47 -04:00
#[ clap(
short ,
long ,
help = " Accept all open trade confirmations. Does not open interactive interface. "
) ]
2022-06-19 10:48:18 -04:00
pub accept_all : bool ,
2022-06-19 14:44:47 -04:00
#[ clap(
short ,
long ,
help = " If submitting a confirmation response fails, exit immediately. "
) ]
2022-06-19 10:48:18 -04:00
pub fail_fast : bool ,
}
2022-06-19 11:14:35 -04:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Remove the authenticator from an account. " ) ]
2022-06-19 11:54:16 -04:00
pub ( crate ) struct ArgsRemove ;
2022-06-19 11:14:35 -04:00
#[ 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 ;
2022-06-20 20:43:53 -04:00
#[ derive(Debug, Clone, Parser) ]
#[ clap(about = " Generate 2FA codes " ) ]
pub ( crate ) struct ArgsCode {
#[ clap(
long ,
help = " Assume the computer's time is correct. Don't ask Steam for the time when generating codes. "
) ]
pub offline : bool ,
}
// HACK: the derive API doesn't support default subcommands, so we are going to make it so that it'll be easier to switch over when it's implemented.
// See: https://github.com/clap-rs/clap/issues/3857
impl From < Args > for ArgsCode {
fn from ( args : Args ) -> Self {
2022-06-21 19:31:17 -04:00
args . code
2022-06-20 20:43:53 -04:00
}
}