Fix ignore case for admin add command

This commit is contained in:
Matthew Searle 2024-08-19 14:36:58 -06:00
parent 676b678b52
commit b04ba00292

View File

@ -2,20 +2,27 @@
clippy::needless_pass_by_ref_mut //until we find a better way for specs 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 common::comp;
use server::persistence::SqlLogMode; use server::persistence::SqlLogMode;
use std::sync::mpsc::Sender; use std::{str::FromStr, sync::mpsc::Sender};
use tracing::error; 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, String> {
comp::AdminRole::from_str(&s.to_lowercase()).map_err(|err| err.to_string())
})
}
#[derive(Clone, Debug, Parser)] #[derive(Clone, Debug, Parser)]
pub enum Admin { pub enum Admin {
/// Adds an admin /// Adds an admin
Add { Add {
/// Name of the admin to whom to assign a role /// Name of the admin to whom to assign a role
username: String, username: String,
/// role to assign to the admin /// Role to assign to the admin
#[arg(ignore_case = true, value_parser = clap::value_parser!(comp::AdminRole))] #[arg(value_parser = admin_role_value_parser())]
role: comp::AdminRole, role: comp::AdminRole,
}, },
Remove { Remove {