Add ability to use root flags after subcommands

This commit is contained in:
bytedream 2023-12-09 17:22:04 +01:00
parent 77609be598
commit f9e431e181
2 changed files with 8 additions and 9 deletions

View file

@ -41,7 +41,7 @@ pub struct Cli {
#[arg( #[arg(
help = "Overwrite the language in which results are returned. Default is your system language" help = "Overwrite the language in which results are returned. Default is your system language"
)] )]
#[arg(long)] #[arg(global = true, long)]
lang: Option<Locale>, lang: Option<Locale>,
#[arg(help = "Enable experimental fixes which may resolve some unexpected errors")] #[arg(help = "Enable experimental fixes which may resolve some unexpected errors")]
@ -50,7 +50,7 @@ pub struct Cli {
If everything works as intended this option isn't needed, but sometimes Crunchyroll mislabels \ If everything works as intended this option isn't needed, but sometimes Crunchyroll mislabels \
the audio of a series/season or episode or returns a wrong season number. This is when using this option might help to solve the issue" the audio of a series/season or episode or returns a wrong season number. This is when using this option might help to solve the issue"
)] )]
#[arg(long, default_value_t = false)] #[arg(global = true, long, default_value_t = false)]
experimental_fixes: bool, experimental_fixes: bool,
#[clap(flatten)] #[clap(flatten)]
@ -59,12 +59,11 @@ pub struct Cli {
#[arg(help = "Use a proxy to route all traffic through")] #[arg(help = "Use a proxy to route all traffic through")]
#[arg(long_help = "Use a proxy to route all traffic through. \ #[arg(long_help = "Use a proxy to route all traffic through. \
Make sure that the proxy can either forward TLS requests, which is needed to bypass the (cloudflare) bot protection, or that it is configured so that the proxy can bypass the protection itself")] Make sure that the proxy can either forward TLS requests, which is needed to bypass the (cloudflare) bot protection, or that it is configured so that the proxy can bypass the protection itself")]
#[clap(long)] #[arg(global = true, long, value_parser = crate::utils::clap::clap_parse_proxy)]
#[arg(value_parser = crate::utils::clap::clap_parse_proxy)]
proxy: Option<Proxy>, proxy: Option<Proxy>,
#[arg(help = "Use custom user agent")] #[arg(help = "Use custom user agent")]
#[clap(long)] #[arg(global = true, long)]
user_agent: Option<String>, user_agent: Option<String>,
#[clap(subcommand)] #[clap(subcommand)]
@ -94,14 +93,14 @@ enum Command {
#[derive(Debug, Parser)] #[derive(Debug, Parser)]
struct Verbosity { struct Verbosity {
#[arg(help = "Verbose output")] #[arg(help = "Verbose output")]
#[arg(short, long)] #[arg(global = true, short, long)]
verbose: bool, verbose: bool,
#[arg(help = "Quiet output. Does not print anything unless it's a error")] #[arg(help = "Quiet output. Does not print anything unless it's a error")]
#[arg( #[arg(
long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout" long_help = "Quiet output. Does not print anything unless it's a error. Can be helpful if you pipe the output to stdout"
)] )]
#[arg(short, long)] #[arg(global = true, short, long)]
quiet: bool, quiet: bool,
} }

View file

@ -48,13 +48,13 @@ pub struct LoginMethod {
#[arg( #[arg(
help = "Login with credentials (email and password). Must be provided as email:password" help = "Login with credentials (email and password). Must be provided as email:password"
)] )]
#[arg(long)] #[arg(global = true, long)]
pub credentials: Option<String>, pub credentials: Option<String>,
#[arg(help = "Login with the etp-rt cookie")] #[arg(help = "Login with the etp-rt cookie")]
#[arg( #[arg(
long_help = "Login with the etp-rt cookie. This can be obtained when you login on crunchyroll.com and extract it from there" long_help = "Login with the etp-rt cookie. This can be obtained when you login on crunchyroll.com and extract it from there"
)] )]
#[arg(long)] #[arg(global = true, long)]
pub etp_rt: Option<String>, pub etp_rt: Option<String>,
#[arg(help = "Login anonymously / without an account")] #[arg(help = "Login anonymously / without an account")]
#[arg(long, default_value_t = false)] #[arg(long, default_value_t = false)]