diff --git a/crates/commands/src/commands.rs b/crates/commands/src/commands.rs index 3326ca1b..9e3c9a13 100644 --- a/crates/commands/src/commands.rs +++ b/crates/commands/src/commands.rs @@ -51,7 +51,8 @@ impl Command { let mut was_parameter = true; for (idx, token) in tokens.iter().enumerate().rev() { match token { - Token::FullString(_) + Token::OpaqueRemainder(_) + | Token::OpaqueString(_) | Token::MemberRef(_) | Token::MemberPrivacyTarget(_) | Token::SystemRef(_) diff --git a/crates/commands/src/commands/config.rs b/crates/commands/src/commands/config.rs index d39024d5..7df70321 100644 --- a/crates/commands/src/commands/config.rs +++ b/crates/commands/src/commands/config.rs @@ -27,7 +27,7 @@ pub fn cmds() -> impl Iterator { cfg, autoproxy, ["timeout", "tm"], - [Disable("toggle"), Reset("reset"), FullString("timeout")] // todo: we should parse duration / time values + [Disable("toggle"), Reset("reset"), OpaqueString("timeout")] // todo: we should parse duration / time values ], "cfg_ap_timeout_update", "Sets the autoproxy timeout" diff --git a/crates/commands/src/commands/member.rs b/crates/commands/src/commands/member.rs index 894e09a6..ac4043ce 100644 --- a/crates/commands/src/commands/member.rs +++ b/crates/commands/src/commands/member.rs @@ -10,7 +10,7 @@ pub fn cmds() -> impl Iterator { [ command!( - [member, new, FullString("name")], + [member, new, OpaqueString("name")], "member_new", "Creates a new system member" ), @@ -30,7 +30,7 @@ pub fn cmds() -> impl Iterator { member, MemberRef("target"), description, - FullString("description") + OpaqueRemainder("description") ], "member_desc_update", "Changes a member's description" diff --git a/crates/commands/src/commands/system.rs b/crates/commands/src/commands/system.rs index 37a67613..b505e23f 100644 --- a/crates/commands/src/commands/system.rs +++ b/crates/commands/src/commands/system.rs @@ -14,7 +14,7 @@ pub fn cmds() -> impl Iterator { ), command!([system, new], "system_new", "Creates a new system"), command!( - [system, new, FullString("name")], + [system, new, OpaqueString("name")], "system_new", "Creates a new system" ), diff --git a/crates/commands/src/lib.rs b/crates/commands/src/lib.rs index abad8c0c..04b66b2f 100644 --- a/crates/commands/src/lib.rs +++ b/crates/commands/src/lib.rs @@ -282,7 +282,7 @@ fn next_token<'a>( // iterate over tokens and run try_match for token in possible_tokens { - let is_match_remaining_token = |token: &Token| matches!(token, Token::FullString(_)); + let is_match_remaining_token = |token: &Token| matches!(token, Token::OpaqueRemainder(_)); // check if this is a token that matches the rest of the input let match_remaining = is_match_remaining_token(token) // check for Any here if it has a "match remainder" token in it diff --git a/crates/commands/src/token.rs b/crates/commands/src/token.rs index 367c85b6..7f736ee5 100644 --- a/crates/commands/src/token.rs +++ b/crates/commands/src/token.rs @@ -20,7 +20,9 @@ pub enum Token { Value(Vec), /// Opaque string (eg. "name" in `pk;member new name`) - FullString(ParamName), + OpaqueString(ParamName), + /// Remainder of a command (eg. "desc" in `pk;member description [desc...]`) + OpaqueRemainder(ParamName), /// Member reference (hid or member name) MemberRef(ParamName), @@ -94,7 +96,8 @@ impl Token { // empty token Self::Empty => Some(Ok(None)), // missing paramaters - Self::FullString(param_name) + Self::OpaqueRemainder(param_name) + | Self::OpaqueString(param_name) | Self::MemberRef(param_name) | Self::MemberPrivacyTarget(param_name) | Self::SystemRef(param_name) @@ -131,11 +134,13 @@ impl Token { .any(|v| v.eq(input)) .then(|| TokenMatchValue::new_match(input)) .unwrap_or(None), - Self::FullString(param_name) => TokenMatchValue::new_match_param( - input, - param_name, - Parameter::OpaqueString { raw: input.into() }, - ), + Self::OpaqueRemainder(param_name) | Self::OpaqueString(param_name) => { + TokenMatchValue::new_match_param( + input, + param_name, + Parameter::OpaqueString { raw: input.into() }, + ) + } Self::SystemRef(param_name) => TokenMatchValue::new_match_param( input, param_name, @@ -227,7 +232,8 @@ impl Display for Token { Token::Value(vec) if vec.is_empty().not() => write!(f, "{}", vec.first().unwrap()), Token::Value(_) => Ok(()), // if value token has no values (lol), don't print anything // todo: it might not be the best idea to directly use param name here (what if we want to display something else but keep the name? or translations?) - Token::FullString(param_name) => write!(f, "[{}]", param_name), + Token::OpaqueRemainder(param_name) => write!(f, "[{}...]", param_name), + Token::OpaqueString(param_name) => write!(f, "[{}]", param_name), Token::MemberRef(param_name) => write!(f, "<{}>", param_name), Token::SystemRef(param_name) => write!(f, "<{}>", param_name), Token::MemberPrivacyTarget(param_name) => write!(f, "<{}>", param_name),