blob: 92866d4f78c1f0e3fa765ee9b5ce9c3d49fa7114 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
|