summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--resources/locales/jvn/en.yml4
-rw-r--r--resources/locales/jvn/zh-CN.yml4
-rw-r--r--src/bin/jvn.rs12
-rw-r--r--src/systems/cmd/errors.rs4
-rw-r--r--src/systems/cmd/macros.rs5
-rw-r--r--src/systems/cmd/processer.rs11
-rw-r--r--templates/_override_renderer_entry.rs.template2
8 files changed, 12 insertions, 31 deletions
diff --git a/Cargo.lock b/Cargo.lock
index bd4b07c..f05db8c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1944,6 +1944,7 @@ dependencies = [
"hex_display",
"just_fmt",
"memmap2",
+ "serde",
"sha2 0.10.9",
"sheet_system_macros",
"thiserror 1.0.69",
diff --git a/resources/locales/jvn/en.yml b/resources/locales/jvn/en.yml
index 8768e6a..801c735 100644
--- a/resources/locales/jvn/en.yml
+++ b/resources/locales/jvn/en.yml
@@ -12,10 +12,6 @@ process_error:
Use `jv -h` to get help
- ambiguous_command: |
- Multiple commands found, unable to determine which one you want:
- %{nodes}
-
no_node_found: |
Unable to find command `%{node}`
diff --git a/resources/locales/jvn/zh-CN.yml b/resources/locales/jvn/zh-CN.yml
index 455ca90..71953a9 100644
--- a/resources/locales/jvn/zh-CN.yml
+++ b/resources/locales/jvn/zh-CN.yml
@@ -11,10 +11,6 @@ process_error:
使用 `jv -h` 查看帮助
- ambiguous_command: |
- 找到多个命令,无法确定您想要哪一个:
- %{nodes}
-
no_node_found: |
无法找到命令 `%{node}`
diff --git a/src/bin/jvn.rs b/src/bin/jvn.rs
index 1dbc517..7ec1f4d 100644
--- a/src/bin/jvn.rs
+++ b/src/bin/jvn.rs
@@ -101,18 +101,6 @@ async fn main() {
CmdProcessError::NoMatchingCommand => {
handle_no_matching_command_error(args);
}
- CmdProcessError::AmbiguousCommand(nodes) => {
- let nodes_list = nodes
- .iter()
- .enumerate()
- .map(|(i, node)| format!("{}. {}", i + 1, node))
- .collect::<Vec<String>>()
- .join("\n");
- eprintln!(
- "{}",
- md(t!("process_error.ambiguous_command", nodes = nodes_list))
- );
- }
CmdProcessError::ParseError(help) => {
if help.trim().len() < 1 {
eprintln!("{}", md(t!("process_error.parse_error")));
diff --git a/src/systems/cmd/errors.rs b/src/systems/cmd/errors.rs
index 0b01abf..abde5de 100644
--- a/src/systems/cmd/errors.rs
+++ b/src/systems/cmd/errors.rs
@@ -8,6 +8,7 @@ pub enum CmdPrepareError {
#[error("{0}")]
Error(String),
+ // Workspace Reader Errors
#[error("LocalWorkspace not found")]
LocalWorkspaceNotFound,
@@ -110,9 +111,6 @@ pub enum CmdProcessError {
#[error("No matching command found")]
NoMatchingCommand,
- #[error("Ambiguous command, multiple matches found")]
- AmbiguousCommand(Vec<String>),
-
#[error("Parse error")]
ParseError(String),
diff --git a/src/systems/cmd/macros.rs b/src/systems/cmd/macros.rs
index c7d576d..23a277c 100644
--- a/src/systems/cmd/macros.rs
+++ b/src/systems/cmd/macros.rs
@@ -161,6 +161,9 @@ macro_rules! command_template {
#[macro_export]
macro_rules! cmd_output {
($v:expr, $t:ty) => {
- Ok((Box::new($v), stringify!($t).to_string()))
+ Ok((
+ Box::new($v) as Box<dyn std::any::Any + Send + 'static>,
+ stringify!($t).to_string(),
+ ))
};
}
diff --git a/src/systems/cmd/processer.rs b/src/systems/cmd/processer.rs
index 4bcaaeb..196764a 100644
--- a/src/systems/cmd/processer.rs
+++ b/src/systems/cmd/processer.rs
@@ -37,12 +37,11 @@ pub async fn jv_cmd_process(
}
_ => {
// Multiple matching nodes found
- return Err(CmdProcessError::AmbiguousCommand(
- matching_nodes
- .iter()
- .map(|s| s.to_string())
- .collect::<Vec<String>>(),
- ));
+ // Find the node with the longest length (most specific match)
+ let matched_prefix = matching_nodes.iter().max_by_key(|node| node.len()).unwrap();
+ let prefix_len = matched_prefix.split_whitespace().count();
+ 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;
}
}
}
diff --git a/templates/_override_renderer_entry.rs.template b/templates/_override_renderer_entry.rs.template
index 06b2c35..8b2130d 100644
--- a/templates/_override_renderer_entry.rs.template
+++ b/templates/_override_renderer_entry.rs.template
@@ -8,6 +8,6 @@ match type_name.as_str() {
.map_err(|_| CmdProcessError::DowncastFailed)?;
include!("../render/_override_renderer_dispatcher.rs")
}
- _ => return Err(CmdProcessError::NoMatchingCommand),
// -- TEMPLATE END --
+ _ => return Err(CmdProcessError::NoMatchingCommand),
}