diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-15 03:28:02 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-15 03:28:02 +0800 |
| commit | ec6c87d12062576271231b88364a4aa00765ae65 (patch) | |
| tree | c1fcc3583aaffa06c0857403b557231719dde1af /mingling_core/src/program/once_exec.rs | |
| parent | 372eb14ab9a9b7fc0e5334ca15a9d8b656140e54 (diff) | |
feat(core): allow pre_dispatch hooks to mutate arguments
Change `HookPreDispatchInfo.arguments` from `&[String]` to `&mut
Vec<String>`
so hooks can rewrite command-line arguments before dispatch.
Diffstat (limited to 'mingling_core/src/program/once_exec.rs')
| -rw-r--r-- | mingling_core/src/program/once_exec.rs | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/mingling_core/src/program/once_exec.rs b/mingling_core/src/program/once_exec.rs index e9927b5..203bbf5 100644 --- a/mingling_core/src/program/once_exec.rs +++ b/mingling_core/src/program/once_exec.rs @@ -25,15 +25,19 @@ where self.run_hook_on_begin(&crate::hook::HookBeginInfo {}); self.args = self.args.iter().skip(1).cloned().collect(); + let mut args = std::mem::take(&mut self.args); #[cfg(not(feature = "async"))] { #[cfg(panic = "abort")] - return self.exec_wrapper(|p| crate::exec::exec(p).map_err(|e| e.into())); + return self + .exec_wrapper(|p| crate::exec::exec_with_args(p, &mut args).map_err(|e| e.into())); #[cfg(not(panic = "abort"))] match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - self.exec_wrapper(|p| crate::exec::exec(p).map_err(std::convert::Into::into)) + self.exec_wrapper(|p| { + crate::exec::exec_with_args(p, &mut args).map_err(std::convert::Into::into) + }) })) { Ok(result) => result, Err(panic_info) => { @@ -60,7 +64,11 @@ where #[cfg(feature = "async")] { return self - .exec_wrapper(|p| async { crate::exec::exec(p).await.map_err(Into::into) }) + .exec_wrapper(|p| async move { + crate::exec::exec_with_args(p, &mut args) + .await + .map_err(Into::into) + }) .await; } } |
