mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 13:06:50 +00:00
refactor(commands): FullString -> OpaqueRemainder and add OpaqueString
This commit is contained in:
parent
2a063442ea
commit
a1f7656276
6 changed files with 21 additions and 14 deletions
|
|
@ -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(_)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
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"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
|
||||
[
|
||||
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<Item = Command> {
|
|||
member,
|
||||
MemberRef("target"),
|
||||
description,
|
||||
FullString("description")
|
||||
OpaqueRemainder("description")
|
||||
],
|
||||
"member_desc_update",
|
||||
"Changes a member's description"
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ pub fn cmds() -> impl Iterator<Item = Command> {
|
|||
),
|
||||
command!([system, new], "system_new", "Creates a new system"),
|
||||
command!(
|
||||
[system, new, FullString("name")],
|
||||
[system, new, OpaqueString("name")],
|
||||
"system_new",
|
||||
"Creates a new system"
|
||||
),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ pub enum Token {
|
|||
Value(Vec<SmolStr>),
|
||||
|
||||
/// Opaque string (eg. "name" in `pk;member new name`)
|
||||
FullString(ParamName),
|
||||
OpaqueString(ParamName),
|
||||
/// Remainder of a command (eg. "desc" in `pk;member <target> 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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue