diff options
| author | Jonas Maier <jonas@x77.dev> | 2026-05-09 11:30:28 +0200 |
|---|---|---|
| committer | Jonas Maier <jonas@x77.dev> | 2026-05-09 11:30:28 +0200 |
| commit | dd24cc2aec9ece8214ec1a4eff4abd26d00ea083 (patch) | |
| tree | 354f4cb1c13ba20291fd57680aafaa4df67b99bf /src/run/mod.rs | |
| parent | edfc7e48c563a97399d18e3ef44fd595c0fd4e45 (diff) | |
| download | pish-dd24cc2aec9ece8214ec1a4eff4abd26d00ea083.tar.gz | |
simple script file test
Diffstat (limited to 'src/run/mod.rs')
| -rw-r--r-- | src/run/mod.rs | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/run/mod.rs b/src/run/mod.rs index 885261b..7e575ce 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -95,12 +95,12 @@ pub struct Executor { expand_commands: bool, } -struct SpawnedPipeline { +pub struct SpawnedPipeline { executors: Vec<SpawnedCmd>, cancel: Vec<Canceler>, } -enum SpawnedCmd { +pub enum SpawnedCmd { Builtin(ThreadWaiter<Result<(), BuiltinError>>), Fun(ThreadWaiter<Result<(), ExecError>>), Child(ChildWaiter), @@ -135,7 +135,7 @@ impl IsSuccessful for Result<(), ExecError> { } impl SpawnedCmd { - fn join(self) -> Result<(), ExecError> { + pub fn join(self) -> Result<(), ExecError> { match self { SpawnedCmd::Builtin(handle) => { handle.into_inner().join().map_err(|_| ExecError::Panic)?? @@ -171,7 +171,7 @@ impl SpawnedCmd { } /// returns whether the spawned command is already joined - fn join_timeout(&mut self, timeout_ms: u16) -> bool { + pub fn join_timeout(&mut self, timeout_ms: u16) -> bool { match self { SpawnedCmd::Builtin(tw) => tw.try_join(timeout_ms), SpawnedCmd::Fun(tw) => tw.try_join(timeout_ms), @@ -185,7 +185,7 @@ impl SpawnedCmd { } } - fn cancel(&mut self) { + pub fn cancel(&mut self) { match self { SpawnedCmd::Pipeline(pipes) => { for c in pipes.cancel.iter_mut() { @@ -226,6 +226,14 @@ impl Executor { } } + pub fn new(se: Arc<Mutex<Session>>) -> Self { + Self { + se, + args: None, + expand_commands: true, + } + } + fn spawn_cmd( &mut self, cmd: CommandKind, @@ -436,6 +444,15 @@ impl Executor { }); SpawnedCmd::Fun(handle) } + + pub fn execute_script( + &mut self, + s: parse::Script, + stdin: InputReader, + stdout: OutputWriter, + ) -> SpawnedCmd { + self.execute_block(parse::Block { commands: s.stmts }, stdin, stdout) + } } impl parse::Expander for Executor { @@ -559,11 +576,7 @@ impl Aliases { } fn exec(se: Arc<Mutex<Session>>, ast: Ast<PreExpansion>) -> Result<(), ExecError> { - let mut exec = Executor { - se: se.clone(), - args: None, - expand_commands: true, - }; + let mut exec = Executor::new(se.clone()); let ast = ast.expand(&mut exec)?; let (stdin, c1) = InputReader::new(Input::Stdin); let (stdout, c2) = OutputWriter::new(Output::Stdout); @@ -587,9 +600,9 @@ pub fn run_quiet( } pub fn run(se: Arc<Mutex<Session>>, parsed: Ast<PreExpansion>) { - se.lock().unwrap().raw.disable(); + se.lock().unwrap().raw_disable(); let result = exec(se.clone(), parsed); - se.lock().unwrap().raw.enable(); + se.lock().unwrap().raw_enable(); if se.lock().unwrap().loud { let status_string = match result { |
