remove OpaqueStringRemainder and use Remainder like intended

This commit is contained in:
dusk 2025-11-23 10:28:46 +00:00
parent 67865263c1
commit d8748b1efc
No known key found for this signature in database
10 changed files with 46 additions and 50 deletions

View file

@ -14,7 +14,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
.help("Shows an abuse log entry"),
command!(abuselog, ("flagdeny", ["fd"]), log_param, Optional(("value", Toggle)) => format!("admin_abuselog_flag_deny_{}", log_param.name()))
.help("Sets the deny flag on an abuse log entry"),
command!(abuselog, ("description", ["desc"]), log_param, Optional(("desc", OpaqueStringRemainder)) => format!("admin_abuselog_description_{}", log_param.name()))
command!(abuselog, ("description", ["desc"]), log_param, Optional(Remainder(("desc", OpaqueString))) => format!("admin_abuselog_description_{}", log_param.name()))
.flag(CLEAR)
.flag(YES)
.help("Sets the description of an abuse log entry"),
@ -27,7 +27,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
].into_iter()
};
let abuselog_cmds = [
command!(abuselog, ("create", ["c", "new"]), ("account", UserRef), Optional(("description", OpaqueStringRemainder)) => "admin_abuselog_create")
command!(abuselog, ("create", ["c", "new"]), ("account", UserRef), Optional(Remainder(("description", OpaqueString))) => "admin_abuselog_create")
.flag(("deny-boy-usage", ["deny"]))
.help("Creates an abuse log entry")
]
@ -66,7 +66,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
.help("Recovers a system"),
command!(admin, ("systemdelete", ["sd"]), SystemRef => "admin_system_delete")
.help("Deletes a system"),
command!(admin, ("sendmessage", ["sendmsg"]), ("account", UserRef), ("content", OpaqueStringRemainder) => "admin_send_message")
command!(admin, ("sendmessage", ["sendmsg"]), ("account", UserRef), Remainder(("content", OpaqueString)) => "admin_send_message")
.help("Sends a message to a user"),
]
.into_iter()

View file

@ -18,7 +18,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let group_new = tokens!(group, ("new", ["n"]));
let group_new_cmd = [
command!(group_new, ("name", OpaqueStringRemainder) => "group_new")
command!(group_new, Remainder(("name", OpaqueString)) => "group_new")
.help("Creates a new group"),
]
.into_iter();
@ -37,7 +37,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(group_name, CLEAR => "group_clear_name")
.flag(YES)
.help("Clears the group's name"),
command!(group_name, ("name", OpaqueStringRemainder) => "group_rename")
command!(group_name, Remainder(("name", OpaqueString)) => "group_rename")
.help("Renames the group"),
]
.into_iter();
@ -49,7 +49,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(group_display_name, CLEAR => "group_clear_display_name")
.flag(YES)
.help("Clears the group's display name"),
command!(group_display_name, ("name", OpaqueStringRemainder) => "group_change_display_name")
command!(group_display_name, Remainder(("name", OpaqueString)) => "group_change_display_name")
.help("Changes the group's display name"),
]
.into_iter();
@ -67,7 +67,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(group_description, CLEAR => "group_clear_description")
.flag(YES)
.help("Clears the group's description"),
command!(group_description, ("description", OpaqueStringRemainder) => "group_change_description")
command!(group_description, Remainder(("description", OpaqueString)) => "group_change_description")
.help("Changes the group's description"),
]
.into_iter();
@ -154,7 +154,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let search = tokens!(
("search", ["find", "query"]),
("query", OpaqueStringRemainder)
Remainder(("query", OpaqueString))
);
let group_list_members = tokens!(group_target, ("members", ["list", "ls"]));
let group_list_members_cmd = [

View file

@ -2,7 +2,7 @@ use super::*;
pub fn cmds() -> impl Iterator<Item = Command> {
[
command!("import", Optional(("url", OpaqueStringRemainder)) => "import").flag(YES),
command!("import", Optional(Remainder(("url", OpaqueString))) => "import").flag(YES),
command!("export" => "export"),
]
.into_iter()

View file

@ -48,7 +48,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let member_name = tokens!(member_target, name);
[
command!(member_name => "member_name_show").help("Shows a member's name"),
command!(member_name, ("name", OpaqueStringRemainder) => "member_name_update")
command!(member_name, Remainder(("name", OpaqueString)) => "member_name_update")
.flag(YES)
.help("Changes a member's name"),
]
@ -62,7 +62,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(member_desc, CLEAR => "member_desc_clear")
.flag(YES)
.help("Clears a member's description"),
command!(member_desc, ("description", OpaqueStringRemainder) => "member_desc_update")
command!(member_desc, Remainder(("description", OpaqueString)) => "member_desc_update")
.help("Changes a member's description"),
]
.into_iter()
@ -87,7 +87,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(member_pronouns => "member_pronouns_show")
.help("Shows a member's pronouns"),
command!(member_pronouns, ("pronouns", OpaqueStringRemainder) => "member_pronouns_update")
command!(member_pronouns, Remainder(("pronouns", OpaqueString)) => "member_pronouns_update")
.help("Changes a member's pronouns"),
command!(member_pronouns, CLEAR => "member_pronouns_clear")
.flag(YES)
@ -139,7 +139,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(member_display_name => "member_displayname_show")
.help("Shows a member's display name"),
command!(member_display_name, ("name", OpaqueStringRemainder) => "member_displayname_update")
command!(member_display_name, Remainder(("name", OpaqueString)) => "member_displayname_update")
.help("Changes a member's display name"),
command!(member_display_name, CLEAR => "member_displayname_clear")
.flag(YES)
@ -152,7 +152,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(member_server_name => "member_servername_show")
.help("Shows a member's server name"),
command!(member_server_name, ("name", OpaqueStringRemainder) => "member_servername_update")
command!(member_server_name, Remainder(("name", OpaqueString)) => "member_servername_update")
.help("Changes a member's server name"),
command!(member_server_name, CLEAR => "member_servername_clear")
.flag(YES)
@ -165,7 +165,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
[
command!(member_proxy => "member_proxy_show")
.help("Shows a member's proxy tags"),
command!(member_proxy, ("tags", OpaqueString) => "member_proxy_set")
command!(member_proxy, Remainder(("tags", OpaqueString)) => "member_proxy_set")
.help("Sets a member's proxy tags"),
command!(member_proxy, ("add", ["a"]), ("tag", OpaqueString) => "member_proxy_add")
.help("Adds proxy tag to a member"),
@ -298,7 +298,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let member_list_group_cmds = [
command!(member_group => "member_list_groups"),
command!(member_group, "list" => "member_list_groups"),
command!(member_group, ("search", ["find", "query"]), ("query", OpaqueStringRemainder) => "member_search_groups"),
command!(member_group, ("search", ["find", "query"]), Remainder(("query", OpaqueString)) => "member_search_groups"),
]
.into_iter()
.map(|cmd| cmd.flags(get_list_flags()));

View file

@ -8,6 +8,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
let reproxy = ("reproxy", ["rp", "crimes", "crime"]);
let edit = ("edit", ["e"]);
let new_content_param = Remainder(("new_content", OpaqueString));
let apply_edit = |cmd: Command| {
cmd.flag(("append", ["a"]))
.flag(("prepend", ["p"]))
@ -25,9 +26,9 @@ pub fn cmds() -> impl Iterator<Item = Command> {
.help("Shows information about a proxied message"),
command!(message, author => "message_author").help("Shows the author of a proxied message"),
command!(message, delete => "message_delete").help("Deletes a proxied message"),
apply_edit(command!(message, edit, ("new_content", OpaqueStringRemainder) => "message_edit_specified")),
apply_edit(command!(edit, Skip(MessageRef), ("new_content", OpaqueStringRemainder) => "message_edit_specified")),
apply_edit(command!(edit, ("new_content", OpaqueStringRemainder) => "message_edit")),
apply_edit(command!(message, edit, new_content_param => "message_edit_specified")),
apply_edit(command!(edit, Skip(MessageRef), new_content_param => "message_edit_specified")),
apply_edit(command!(edit, new_content_param => "message_edit")),
command!(reproxy, ("member", MemberRef) => "message_reproxy")
.help("Reproxies a message with a different member"),
command!(reproxy, ("msg", MessageRef), ("member", MemberRef) => "message_reproxy_specified")

View file

@ -20,7 +20,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
command!(switch, ("commands", ["help"]) => "switch_commands"),
command!(switch, out => "switch_out"),
command!(switch, delete => "switch_delete").flag(("all", ["clear", "c"])),
command!(switch, r#move, OpaqueStringRemainder => "switch_move"), // TODO: datetime parsing
command!(switch, r#move, Remainder(OpaqueString) => "switch_move"), // TODO: datetime parsing
command!(switch, edit, out => "switch_edit_out").flag(YES),
command!(switch, edit, Optional(MemberRefs) => "switch_edit").flags(edit_flags),
command!(switch, copy, Optional(MemberRefs) => "switch_copy").flags(edit_flags),

View file

@ -23,7 +23,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
let system_new = tokens!(system, ("new", ["n"]));
let system_new_cmd = [
command!(system_new => "system_new").help("Creates a new system"),
command!(system_new, ("name", OpaqueStringRemainder) => "system_new_name")
command!(system_new, Remainder(("name", OpaqueString)) => "system_new_name")
.help("Creates a new system (using the provided name)"),
]
.into_iter();
@ -62,7 +62,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_name_self, CLEAR => "system_clear_name")
.flag(YES)
.help("Clears your system's name"),
command!(system_name_self, ("name", OpaqueStringRemainder) => "system_rename")
command!(system_name_self, Remainder(("name", OpaqueString)) => "system_rename")
.help("Renames your system"),
]
.into_iter();
@ -80,7 +80,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_server_name_self, CLEAR => "system_clear_server_name")
.flag(YES)
.help("Clears your system's server name"),
command!(system_server_name_self, ("name", OpaqueStringRemainder) => "system_rename_server_name")
command!(system_server_name_self, Remainder(("name", OpaqueString)) => "system_rename_server_name")
.help("Renames your system's server name"),
]
.into_iter();
@ -97,7 +97,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_description_self, CLEAR => "system_clear_description")
.flag(YES)
.help("Clears your system's description"),
command!(system_description_self, ("description", OpaqueStringRemainder) => "system_change_description")
command!(system_description_self, Remainder(("description", OpaqueString)) => "system_change_description")
.help("Changes your system's description"),
]
.into_iter();
@ -128,7 +128,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_tag_self, CLEAR => "system_clear_tag")
.flag(YES)
.help("Clears your system's tag"),
command!(system_tag_self, ("tag", OpaqueStringRemainder) => "system_change_tag")
command!(system_tag_self, Remainder(("tag", OpaqueString)) => "system_change_tag")
.help("Changes your system's tag"),
]
.into_iter();
@ -146,7 +146,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_server_tag_self, CLEAR => "system_clear_server_tag")
.flag(YES)
.help("Clears your system's server tag"),
command!(system_server_tag_self, ("tag", OpaqueStringRemainder) => "system_change_server_tag")
command!(system_server_tag_self, Remainder(("tag", OpaqueString)) => "system_change_server_tag")
.help("Changes your system's server tag"),
]
.into_iter();
@ -163,7 +163,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
command!(system_pronouns_self, CLEAR => "system_clear_pronouns")
.flag(YES)
.help("Clears your system's pronouns"),
command!(system_pronouns_self, ("pronouns", OpaqueStringRemainder) => "system_change_pronouns")
command!(system_pronouns_self, Remainder(("pronouns", OpaqueString)) => "system_change_pronouns")
.help("Changes your system's pronouns"),
]
.into_iter();
@ -274,7 +274,7 @@ pub fn edit() -> impl Iterator<Item = Command> {
let system_list = tokens!("members", list);
let search = tokens!(
("search", ["query", "find"]),
("query", OpaqueStringRemainder),
Remainder(("query", OpaqueString))
);
let add_list_flags = |cmd: Command| cmd.flags(get_list_flags());
let system_list_cmd = [

View file

@ -12,7 +12,6 @@ use crate::token::{Token, TokenMatchResult};
pub enum ParameterKind {
OpaqueString,
OpaqueInt,
OpaqueStringRemainder,
MemberRef,
MemberRefs,
GroupRef,
@ -36,7 +35,6 @@ impl ParameterKind {
match self {
ParameterKind::OpaqueString => "string",
ParameterKind::OpaqueInt => "number",
ParameterKind::OpaqueStringRemainder => "string",
ParameterKind::MemberRef => "target",
ParameterKind::MemberRefs => "targets",
ParameterKind::GroupRef => "target",
@ -80,13 +78,6 @@ pub enum ParameterValue {
Null,
}
fn is_remainder(kind: ParameterKind) -> bool {
matches!(
kind,
ParameterKind::OpaqueStringRemainder | ParameterKind::MemberRefs | ParameterKind::GroupRefs
)
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Parameter {
name: SmolStr,
@ -135,9 +126,7 @@ impl Parameter {
pub fn match_value(&self, input: &str) -> Result<ParameterValue, SmolStr> {
match self.kind {
// TODO: actually parse image url
ParameterKind::OpaqueString | ParameterKind::OpaqueStringRemainder => {
Ok(ParameterValue::OpaqueString(input.into()))
}
ParameterKind::OpaqueString => Ok(ParameterValue::OpaqueString(input.into())),
ParameterKind::OpaqueInt => input
.parse::<i32>()
.map(|num| ParameterValue::OpaqueInt(num))
@ -254,13 +243,10 @@ impl Display for Parameter {
ParameterKind::OpaqueInt => {
write!(f, "[{}]", self.name)
}
ParameterKind::OpaqueStringRemainder => {
write!(f, "[{}]...", self.name)
}
ParameterKind::MemberRef => write!(f, "<target member>"),
ParameterKind::MemberRefs => write!(f, "<member 1> <member 2> <member 3>..."),
ParameterKind::MemberRefs => write!(f, "<member 1> <member 2> <member 3>"),
ParameterKind::GroupRef => write!(f, "<target group>"),
ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>..."),
ParameterKind::GroupRefs => write!(f, "<group 1> <group 2> <group 3>"),
ParameterKind::SystemRef => write!(f, "<target system>"),
ParameterKind::UserRef => write!(f, "<target user>"),
ParameterKind::MessageRef => write!(f, "<target message>"),
@ -273,10 +259,18 @@ impl Display for Parameter {
ParameterKind::Toggle => write!(f, "<on|off>"),
ParameterKind::Avatar => write!(f, "<url|@mention>"),
ParameterKind::ProxySwitchAction => write!(f, "<new|add|off>"),
}?;
if self.is_remainder() {
write!(f, "...")?;
}
Ok(())
}
}
fn is_remainder(kind: ParameterKind) -> bool {
matches!(kind, ParameterKind::MemberRefs | ParameterKind::GroupRefs)
}
impl From<ParameterKind> for Parameter {
fn from(value: ParameterKind) -> Self {
Parameter {
@ -301,6 +295,7 @@ impl From<(&str, ParameterKind)> for Parameter {
}
}
/// if no input is left to parse, this parameter matches to Null
#[derive(Clone)]
pub struct Optional<P: Into<Parameter>>(pub P);
@ -311,6 +306,7 @@ impl<P: Into<Parameter>> From<Optional<P>> for Parameter {
}
}
/// tells the parser to use the remainder of the input as the input to this parameter
#[derive(Clone)]
pub struct Remainder<P: Into<Parameter>>(pub P);
@ -321,8 +317,7 @@ impl<P: Into<Parameter>> From<Remainder<P>> for Parameter {
}
}
// todo(dusk): this is kind of annoying to use, should probably introduce
// a way to match multiple parameters in a single parameter
/// skips the branch this parameter is in if it does not match
#[derive(Clone)]
pub struct Skip<P: Into<Parameter>>(pub P);

View file

@ -1,4 +1,4 @@
use std::{collections::HashMap, fmt::Write, usize};
use std::{collections::HashMap, fmt::Write};
use command_parser::{parameter::ParameterValue, token::TokenMatchResult, Tree};

View file

@ -262,7 +262,7 @@ fn command_callback_to_name(cb: &str) -> String {
fn get_param_ty(kind: ParameterKind) -> &'static str {
match kind {
ParameterKind::OpaqueString | ParameterKind::OpaqueStringRemainder => "string",
ParameterKind::OpaqueString => "string",
ParameterKind::OpaqueInt => "int",
ParameterKind::MemberRef => "PKMember",
ParameterKind::MemberRefs => "List<PKMember>",
@ -285,7 +285,7 @@ fn get_param_ty(kind: ParameterKind) -> &'static str {
fn get_param_param_ty(kind: ParameterKind) -> &'static str {
match kind {
ParameterKind::OpaqueString | ParameterKind::OpaqueStringRemainder => "Opaque",
ParameterKind::OpaqueString => "Opaque",
ParameterKind::OpaqueInt => "Number",
ParameterKind::MemberRef => "Member",
ParameterKind::MemberRefs => "Members",