summaryrefslogtreecommitdiff
path: root/src/Command/JobId.hs
blob: 9f531d65f06a555f20d650b7bf59e94c3abc9f45 (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
module Command.JobId (
    JobIdCommand,
) where

import Control.Monad.IO.Class

import Data.Text (Text)
import Data.Text qualified as T
import Data.Text.IO qualified as T

import Command
import Eval
import Job.Types


data JobIdCommand = JobIdCommand JobRef

instance Command JobIdCommand where
    commandName _ = "jobid"
    commandDescription _ = "Resolve job reference to canonical job ID"

    type CommandArguments JobIdCommand = Text

    commandUsage _ = T.pack $ unlines $
        [ "Usage: minici jobid <job ref>"
        ]

    commandInit _ _ = JobIdCommand . JobRef . T.splitOn "."
    commandExec = cmdJobId


cmdJobId :: JobIdCommand -> CommandExec ()
cmdJobId (JobIdCommand ref) = do
    config <- getConfig
    einput <- getEvalInput
    JobId ids <- either (tfail . textEvalError) return =<<
        liftIO (runEval (evalJobReference config ref) einput)

    liftIO $ T.putStrLn $ T.intercalate "." $ map textJobIdPart ids