diff --git a/server-cli/src/cli.rs b/server-cli/src/cli.rs index 2dad16a398..572528ff9c 100644 --- a/server-cli/src/cli.rs +++ b/server-cli/src/cli.rs @@ -2,20 +2,27 @@ clippy::needless_pass_by_ref_mut //until we find a better way for specs )] -use clap::Parser; +use clap::{builder::ValueParser, Parser}; use common::comp; use server::persistence::SqlLogMode; -use std::sync::mpsc::Sender; +use std::{str::FromStr, sync::mpsc::Sender}; use tracing::error; +// Custom value parser for case-insensitive parsing of AdminRole +fn admin_role_value_parser() -> ValueParser { + ValueParser::new(move |s: &str| -> Result { + comp::AdminRole::from_str(&s.to_lowercase()).map_err(|err| err.to_string()) + }) +} + #[derive(Clone, Debug, Parser)] pub enum Admin { /// Adds an admin Add { /// Name of the admin to whom to assign a role username: String, - /// role to assign to the admin - #[arg(ignore_case = true, value_parser = clap::value_parser!(comp::AdminRole))] + /// Role to assign to the admin + #[arg(value_parser = admin_role_value_parser())] role: comp::AdminRole, }, Remove {