diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-14 21:32:51 +0200 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-15 20:22:16 +0200 | 
| commit | dd028e6043d2b3d6751e6a002fb49dbb48a8dcfd (patch) | |
| tree | 0541d233edddc6ca231144e52b726080588e1ddd /src/Command | |
| parent | 364c3cf920ea3ba41af9f8e0a0a6a9efd0edbafa (diff) | |
Log command
Changelog: Added `log` command to show job log
Diffstat (limited to 'src/Command')
| -rw-r--r-- | src/Command/Log.hs | 45 | 
1 files changed, 45 insertions, 0 deletions
| diff --git a/src/Command/Log.hs b/src/Command/Log.hs new file mode 100644 index 0000000..92866d4 --- /dev/null +++ b/src/Command/Log.hs @@ -0,0 +1,45 @@ +module Command.Log ( +    LogCommand, +) where + +import Control.Monad.IO.Class + +import Data.Text (Text) +import Data.Text qualified as T +import Data.Text.Lazy qualified as TL +import Data.Text.Lazy.IO qualified as TL + +import System.FilePath + +import Command +import Eval +import Job +import Job.Types +import Output + + +data LogCommand = LogCommand JobRef + +instance Command LogCommand where +    commandName _ = "log" +    commandDescription _ = "Show log for the given job" + +    type CommandArguments LogCommand = Text + +    commandUsage _ = T.pack $ unlines $ +        [ "Usage: minici log <job ref>" +        ] + +    commandInit _ _ = LogCommand . JobRef . T.splitOn "." +    commandExec = cmdLog + + +cmdLog :: LogCommand -> CommandExec () +cmdLog (LogCommand ref) = do +    einput <- getEvalInput +    jid <- either (tfail . textEvalError) return =<< +        liftIO (runEval (evalJobReference ref) einput) +    output <- getOutput +    storageDir <- getStorageDir +    liftIO $ mapM_ (outputEvent output . OutputMessage . TL.toStrict) . TL.lines =<< +        TL.readFile (storageDir </> jobStorageSubdir jid </> "log") |