summaryrefslogtreecommitdiff
path: root/src/Script/Shell.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2026-08-22 22:10:51 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2026-08-22 22:10:51 +0200
commit0ba7a3adcc5e539a31b5893bc956a39105e6a9bf (patch)
tree9bb1cbf98c3ee4e65367d73fa0c272a962a1b826 /src/Script/Shell.hs
parentb7638754c0856b1bb5f911985190419ecb5e267b (diff)
Shell: track exit code of the last command
Diffstat (limited to 'src/Script/Shell.hs')
-rw-r--r--src/Script/Shell.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/Script/Shell.hs b/src/Script/Shell.hs
index 29e2324..f070de5 100644
--- a/src/Script/Shell.hs
+++ b/src/Script/Shell.hs
@@ -47,6 +47,7 @@ data ShellState = ShellState
{ shellWorkingDirectory :: FilePath
, shellOldWorkingDirectory :: FilePath
, shellExitOnError :: Bool
+ , shellLastExitCode :: ExitCode
}
data ShellStatement = ShellStatement
@@ -134,17 +135,17 @@ executeCommand sei@ShellExecInfo {..} st pstdin pstdout pstderr scmd@ShellComman
_ -> do
return cur
- ( getExitStatus, state' ) <- executeCommandProcess sei st (handledHandle pstdin') (handledHandle pstdout') (handledHandle pstderr') args cmdCommand
+ ( getExitStatus, st' ) <- executeCommandProcess sei st (handledHandle pstdin') (handledHandle pstdout') (handledHandle pstderr') args cmdCommand
let failedWithStatus status = do
when (shellExitOnError st) $ do
liftIO $ putMVar seiStatusVar status
throwError Failed
- return state'
+ return st' { shellLastExitCode = status }
mapM_ closeIfRequested [ pstdin', pstdout', pstderr' ]
getExitStatus >>= \case
Exited ExitSuccess -> do
- return state'
+ return st' { shellLastExitCode = ExitSuccess }
Exited status -> do
outLine OutputChildFail (Just $ textProcName seiProcName) $ "failed at: " <> textSourceLine cmdSourceLine
failedWithStatus status
@@ -243,11 +244,12 @@ executeScript sei@ShellExecInfo {..} pstdin pstdout pstderr (ShellScript stateme
{ shellWorkingDirectory = nodeDir seiNode
, shellOldWorkingDirectory = nodeDir seiNode
, shellExitOnError = True
+ , shellLastExitCode = ExitSuccess
}
- _ <- (\f -> foldM f initialState statements) $ \st ShellStatement {..} -> do
+ finalState <- (\f -> foldM f initialState statements) $ \st ShellStatement {..} -> do
executePipeline sei st (KeepHandle pstdin) (KeepHandle pstdout) (KeepHandle pstderr) shellPipeline
- liftIO $ putMVar seiStatusVar ExitSuccess
+ liftIO $ putMVar seiStatusVar (shellLastExitCode finalState)
spawnShell :: Node -> ProcName -> ShellScript -> TestRun Process
spawnShell procNode procName script = do