diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-18 17:25:29 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-18 17:26:37 +0800 |
| commit | da5a750965dbec5a2c003faa8fb9f1dd110ccce8 (patch) | |
| tree | b793769ec40494c1ab056c65748c3393b5a849ed /mingling_core/src/program/exec.rs | |
| parent | ab7c5785fb290541ad4361c0d46241817c3ff5f9 (diff) | |
Implement REPL execution with hooks and argument splitting
Diffstat (limited to 'mingling_core/src/program/exec.rs')
| -rw-r--r-- | mingling_core/src/program/exec.rs | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index 1b756a1..72a20b9 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -15,14 +15,35 @@ pub async fn exec<C>( where C: ProgramCollect<Enum = C>, { + let args = program.args.clone(); + exec_with_args(program, args).await +} + +#[cfg(not(feature = "async"))] +pub fn exec<C>(program: &'static Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> +where + C: ProgramCollect<Enum = C>, +{ + let args = program.args.clone(); + exec_with_args(program, args) +} + +#[cfg(feature = "async")] +pub async fn exec_with_args<C>( + program: &'static Program<C>, + args: Vec<String>, +) -> Result<RenderResult, ProgramInternalExecuteError> +where + C: ProgramCollect<Enum = C>, +{ // Run hooks - program.run_hook_pre_dispatch(&program.args); + program.run_hook_pre_dispatch(&args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &program.args)?; + let mut current = dispatch_args_dynamic(program, &args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&program.args)?; + let mut current = C::dispatch_args_trie(&args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -102,18 +123,21 @@ where } #[cfg(not(feature = "async"))] -pub fn exec<C>(program: &'static Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> +pub fn exec_with_args<C>( + program: &'static Program<C>, + args: Vec<String>, +) -> Result<RenderResult, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C>, { // Run hooks - program.run_hook_pre_dispatch(&program.args); + program.run_hook_pre_dispatch(&args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &program.args)?; + let mut current = dispatch_args_dynamic(program, &args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&program.args)?; + let mut current = C::dispatch_args_trie(&args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -212,7 +236,7 @@ where } Err(ProgramInternalExecuteError::DispatcherNotFound) => { // No matching Dispatcher is found - C::build_dispatcher_not_found(program.args.clone()) + C::build_dispatcher_not_found(args.clone()) } Err(e) => return Err(e), }; |
