From b04ba002929140fa1513a68bedaa99237282b679 Mon Sep 17 00:00:00 2001 From: Matthew Searle Date: Mon, 19 Aug 2024 14:36:58 -0600 Subject: [PATCH] Fix ignore case for admin add command --- server-cli/src/cli.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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 {