Adds Flag to ArgumentSpec to support server command arguments like 'kill_npcs --also-pets'

This commit is contained in:
Tim Vincent 2024-01-19 19:15:06 -08:00
parent 33126c8771
commit cb1a0b9f91
3 changed files with 13 additions and 1 deletions

View File

@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added day duration slider configuration on map creation UI. - Added day duration slider configuration on map creation UI.
- Potion of Agility - Potion of Agility
- A way for servers to specify must-accept rules for players - A way for servers to specify must-accept rules for players
- A flag argument type for commands
### Changed ### Changed

View File

@ -604,7 +604,9 @@ impl ServerChatCommand {
Some(Moderator), Some(Moderator),
), ),
ServerChatCommand::Kill => cmd(vec![], "Kill yourself", None), ServerChatCommand::Kill => cmd(vec![], "Kill yourself", None),
ServerChatCommand::KillNpcs => cmd(vec![], "Kill the NPCs", Some(Admin)), ServerChatCommand::KillNpcs => {
cmd(vec![Flag("--also-pets")], "Kill the NPCs", Some(Admin))
},
ServerChatCommand::Kit => cmd( ServerChatCommand::Kit => cmd(
vec![Enum("kit_name", KITS.to_vec(), Required)], vec![Enum("kit_name", KITS.to_vec(), Required)],
"Place a set of items into your inventory.", "Place a set of items into your inventory.",
@ -1078,6 +1080,7 @@ impl ServerChatCommand {
ArgumentSpec::SubCommand => "{} {/.*/}", ArgumentSpec::SubCommand => "{} {/.*/}",
ArgumentSpec::Enum(_, _, _) => "{}", ArgumentSpec::Enum(_, _, _) => "{}",
ArgumentSpec::Boolean(_, _, _) => "{}", ArgumentSpec::Boolean(_, _, _) => "{}",
ArgumentSpec::Flag(_) => "{}",
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(" ") .join(" ")
@ -1148,6 +1151,8 @@ pub enum ArgumentSpec {
/// * suggested tab-completion /// * suggested tab-completion
/// * whether it's optional /// * whether it's optional
Boolean(&'static str, String, Requirement), Boolean(&'static str, String, Requirement),
/// The argument is a flag that enables or disables a feature.
Flag(&'static str),
} }
impl ArgumentSpec { impl ArgumentSpec {
@ -1224,6 +1229,9 @@ impl ArgumentSpec {
format!("[{}]", label) format!("[{}]", label)
} }
}, },
ArgumentSpec::Flag(label) => {
format!("[{}]", label)
},
} }
} }
@ -1239,6 +1247,7 @@ impl ArgumentSpec {
| ArgumentSpec::Message(r) | ArgumentSpec::Message(r)
| ArgumentSpec::Enum(_, _, r) | ArgumentSpec::Enum(_, _, r)
| ArgumentSpec::Boolean(_, _, r) => *r, | ArgumentSpec::Boolean(_, _, r) => *r,
ArgumentSpec::Flag(_) => Requirement::Optional,
ArgumentSpec::SubCommand => Requirement::Required, ArgumentSpec::SubCommand => Requirement::Required,
} }
} }

View File

@ -101,6 +101,7 @@ impl ClientChatCommand {
ArgumentSpec::SubCommand => "{} {/.*/}", ArgumentSpec::SubCommand => "{} {/.*/}",
ArgumentSpec::Enum(_, _, _) => "{}", ArgumentSpec::Enum(_, _, _) => "{}",
ArgumentSpec::Boolean(_, _, _) => "{}", ArgumentSpec::Boolean(_, _, _) => "{}",
ArgumentSpec::Flag(_) => "{}",
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(" ") .join(" ")
@ -595,6 +596,7 @@ impl TabComplete for ArgumentSpec {
.filter(|string| string.starts_with(part)) .filter(|string| string.starts_with(part))
.map(|c| c.to_string()) .map(|c| c.to_string())
.collect(), .collect(),
ArgumentSpec::Flag(part) => vec![part.to_string()],
} }
} }
} }