From 357e012525f21586f4bd614852158c0815fa0faf Mon Sep 17 00:00:00 2001 From: Kiril Kovachev Date: Fri, 9 May 2025 12:13:39 +0100 Subject: [PATCH] feat: Add ArgGroup to allow choice of multiple possible auth methods --- src/main.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.rs b/src/main.rs index 2a6f6de..d62b730 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,27 @@ struct Cli { action: Action, } +#[derive(clap::Args, Debug, Clone, Eq, PartialEq, PartialOrd, Ord)] +#[group(required = true, multiple = false)] +struct AuthMethodParse { + password: Option, + oauth2_token: Option +} + +enum AuthMethod { + Password(String), + OAuth2Token(String) +} + +impl From for AuthMethod { + fn from (parsed_args: AuthMethodParse) -> AuthMethod { + match parsed_args.password { + None => Self::OAuth2Token(parsed_args.oauth2_token.unwrap()), + Some(password) => Self::Password(password) + } + } +} + #[derive(Parser, Clone, Eq, PartialEq, PartialOrd, Ord)] struct SetupArgs { /// Specify the username of the bot