Merge branch 'matsuuii/fix_case_ignore_in_server_cli' into 'master'

Fix ignore case for admin add command

Closes #2000

See merge request veloren/veloren!4561
This commit is contained in:
Marcel 2024-08-19 21:55:43 +00:00
commit 8361d2edfd

View File

@ -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, String> {
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 {