diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-04-11 18:29:57 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-04-11 18:29:57 +0800 |
| commit | 1eb5306fe6e0e09970b37d267051589d8133a824 (patch) | |
| tree | 67dc49cd20ec213ed674e877268cd69633e68690 /mingling_core/src/program | |
| parent | 0b9d890fd9764fa3ec0b749f4b15610e49e3cb8d (diff) | |
Implement basic command completion with shell support
Diffstat (limited to 'mingling_core/src/program')
| -rw-r--r-- | mingling_core/src/program/exec.rs | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index 072f4cb..71d73e6 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -21,7 +21,7 @@ where let mut stop_next = false; // Match user input - match match_user_input(&program) { + match match_user_input(&program, program.args.clone()) { Ok((dispatcher, args)) => { // Entry point current = match dispatcher.begin(args) { @@ -75,13 +75,14 @@ where #[allow(clippy::type_complexity)] pub fn match_user_input<C, G>( program: &Program<C, G>, + args: Vec<String>, ) -> Result<(&Box<dyn Dispatcher<G> + Send + Sync>, Vec<String>), ProgramInternalExecuteError> where C: ProgramCollect<Enum = G>, G: Display, { let nodes = program.get_nodes(); - let command = format!("{} ", program.args.join(" ")); + let command = format!("{} ", args.join(" ")); // Find all nodes that match the command prefix let matching_nodes: Vec<&(String, &Box<dyn Dispatcher<G> + Send + Sync>)> = nodes @@ -98,7 +99,7 @@ where 1 => { let matched_prefix = matching_nodes[0]; let prefix_len = matched_prefix.0.split_whitespace().count(); - let trimmed_args: Vec<String> = program.args.iter().skip(prefix_len).cloned().collect(); + let trimmed_args: Vec<String> = args.iter().skip(prefix_len).cloned().collect(); Ok((matched_prefix.1, trimmed_args)) } _ => { @@ -110,7 +111,7 @@ where .unwrap(); let prefix_len = matched_prefix.0.split_whitespace().count(); - let trimmed_args: Vec<String> = program.args.iter().skip(prefix_len).cloned().collect(); + let trimmed_args: Vec<String> = args.iter().skip(prefix_len).cloned().collect(); Ok((matched_prefix.1, trimmed_args)) } } |
