diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-01-23 04:49:34 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-01-23 04:49:34 +0800 |
| commit | 626536ce51975b051fea087620bc1eb7f6bc69d3 (patch) | |
| tree | b24916b22012d9b8b3b09366bca9911781e6d596 /src/systems/cmd/processer.rs | |
| parent | f607f6ac3b98d00370f613e674da7beb4c61ce58 (diff) | |
Reorganize project structure into systems and assets
Diffstat (limited to 'src/systems/cmd/processer.rs')
| -rw-r--r-- | src/systems/cmd/processer.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/systems/cmd/processer.rs b/src/systems/cmd/processer.rs new file mode 100644 index 0000000..d357e44 --- /dev/null +++ b/src/systems/cmd/processer.rs @@ -0,0 +1,41 @@ +use crate::systems::cmd::_registry::{jv_cmd_nodes, jv_cmd_process_node}; +use crate::systems::cmd::cmd_system::JVCommandContext; +use crate::systems::cmd::errors::CmdProcessError; +use crate::systems::cmd::renderer::JVRenderResult; + +pub async fn jv_cmd_process( + 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 + let matching_nodes: Vec<&String> = nodes + .iter() + .filter(|node| command.starts_with(node.as_str())) + .collect(); + + match matching_nodes.len() { + 0 => { + // No matching node found + return Err(CmdProcessError::NoMatchingCommand); + } + 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(); + return jv_cmd_process_node(matched_prefix, trimmed_args, ctx, renderer_override).await; + } + _ => { + // Multiple matching nodes found + return Err(CmdProcessError::AmbiguousCommand( + matching_nodes + .iter() + .map(|s| s.to_string()) + .collect::<Vec<String>>(), + )); + } + } +} |
