summaryrefslogtreecommitdiff
path: root/src/systems
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-01-24 07:03:40 +0800
committer魏曹先生 <1992414357@qq.com>2026-01-24 07:03:40 +0800
commit3fa56b997b44caba630a5dbc67687923978c5c7d (patch)
treeb1f62fe31f88fb666e810637df8ca7a60265a3ee /src/systems
parent92f2cdd3dfa378cfcfb9085fedd601b27e499ee7 (diff)
Add command aliases, error handling improvements, and flag aliases
- Add aliases for status command: sign, sheet, sheet.add, drop, drop.cat - Improve error handling with detailed localized messages for prepare, execute, and render phases - Add flag aliases: -L for --lang and -R for --renderer - Implement similar command suggestions using Levenshtein distance - Fix command matching logic to avoid ambiguous prefix issues
Diffstat (limited to 'src/systems')
-rw-r--r--src/systems/cmd/processer.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/systems/cmd/processer.rs b/src/systems/cmd/processer.rs
index d357e44..7c464a2 100644
--- a/src/systems/cmd/processer.rs
+++ b/src/systems/cmd/processer.rs
@@ -4,17 +4,24 @@ use crate::systems::cmd::errors::CmdProcessError;
use crate::systems::cmd::renderer::JVRenderResult;
pub async fn jv_cmd_process(
- args: Vec<String>,
+ args: &Vec<String>,
ctx: JVCommandContext,
renderer_override: String,
) -> Result<JVRenderResult, CmdProcessError> {
let nodes = jv_cmd_nodes();
- let command = args.join(" ");
- // Find nodes that match the beginning of the command
+ // Why add a space?
+ // Add a space at the end of the command string for precise command prefix matching.
+ // For example: when the input command is "bananas", if there are two commands "banana" and "bananas",
+ // without a space it might incorrectly match "banana" (because "bananas".starts_with("banana") is true).
+ // After adding a space, "bananas " will not match "banana ", thus avoiding ambiguity caused by overlapping prefixes.
+ let command = format!("{} ", args.join(" "));
+
+ // Find all nodes that match the command prefix
let matching_nodes: Vec<&String> = nodes
.iter()
- .filter(|node| command.starts_with(node.as_str()))
+ // Also add a space to the node string to ensure consistent matching logic
+ .filter(|node| command.starts_with(&format!("{} ", node)))
.collect();
match matching_nodes.len() {
@@ -25,7 +32,7 @@ pub async fn jv_cmd_process(
1 => {
let matched_prefix = matching_nodes[0];
let prefix_len = matched_prefix.split_whitespace().count();
- let trimmed_args: Vec<String> = args.into_iter().skip(prefix_len).collect();
+ let trimmed_args: Vec<String> = args.into_iter().cloned().skip(prefix_len).collect();
return jv_cmd_process_node(matched_prefix, trimmed_args, ctx, renderer_override).await;
}
_ => {