diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-20 22:58:16 +0200 | 
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-04-22 20:54:25 +0200 | 
| commit | 2ee87680556ccf26ef8d415950e7f31034d647c4 (patch) | |
| tree | 376adaa01623892213463507c25d17e042055c2b /src/Command | |
| parent | ce477ae0b39b97a82a86776e076492120e3180eb (diff) | |
Verbose option for ‘jobid’ command
Diffstat (limited to 'src/Command')
| -rw-r--r-- | src/Command/JobId.hs | 47 | ||||
| -rw-r--r-- | src/Command/Run.hs | 8 | 
2 files changed, 45 insertions, 10 deletions
| diff --git a/src/Command/JobId.hs b/src/Command/JobId.hs index d0a85db..1cfd18c 100644 --- a/src/Command/JobId.hs +++ b/src/Command/JobId.hs @@ -2,18 +2,26 @@ module Command.JobId (      JobIdCommand,  ) where +import Control.Monad  import Control.Monad.IO.Class  import Data.Text (Text)  import Data.Text qualified as T -import Data.Text.IO qualified as T + +import System.Console.GetOpt  import Command  import Eval  import Job.Types +import Output +import Repo + +data JobIdCommand = JobIdCommand JobIdOptions JobRef -data JobIdCommand = JobIdCommand JobRef +data JobIdOptions = JobIdOptions +    { joVerbose :: Bool +    }  instance Command JobIdCommand where      commandName _ = "jobid" @@ -22,17 +30,44 @@ instance Command JobIdCommand where      type CommandArguments JobIdCommand = Text      commandUsage _ = T.pack $ unlines $ -        [ "Usage: minici jobid <job ref>" +        [ "Usage: minici jobid [<option>...] <job ref>" +        ] + +    type CommandOptions JobIdCommand = JobIdOptions +    defaultCommandOptions _ = JobIdOptions +        { joVerbose = False +        } + +    commandOptions _ = +        [ Option [ 'v' ] [ "verbose" ] +            (NoArg $ \opts -> opts { joVerbose = True }) +            "show detals of the ID"          ] -    commandInit _ _ = JobIdCommand . JobRef . T.splitOn "." +    commandInit _ opts = JobIdCommand opts . JobRef . T.splitOn "."      commandExec = cmdJobId  cmdJobId :: JobIdCommand -> CommandExec () -cmdJobId (JobIdCommand ref) = do +cmdJobId (JobIdCommand JobIdOptions {..} ref) = do      einput <- getEvalInput +    out <- getOutput      JobId ids <- either (tfail . textEvalError) return =<<          liftIO (runEval (evalJobReference ref) einput) -    liftIO $ T.putStrLn $ textJobId $ JobId ids +    outputMessage out $ textJobId $ JobId ids +    when joVerbose $ do +        outputMessage out "" +        forM_ ids $ \case +            JobIdName name -> outputMessage out $ textJobName name <> " (job name)" +            JobIdCommit mbrepo cid -> outputMessage out $ T.concat +                [ textCommitId cid, " (commit" +                , maybe "" (\name -> " from ‘" <> textRepoName name <> "’ repo") mbrepo +                , ")" +                ] +            JobIdTree mbrepo subtree cid -> outputMessage out $ T.concat +                [ textTreeId cid, " (tree" +                , maybe "" (\name -> " from ‘" <> textRepoName name <> "’ repo") mbrepo +                , if not (null subtree) then ", subtree ‘" <> T.pack subtree <> "’" else "" +                , ")" +                ] diff --git a/src/Command/Run.hs b/src/Command/Run.hs index 593412c..6190236 100644 --- a/src/Command/Run.hs +++ b/src/Command/Run.hs @@ -136,7 +136,7 @@ argumentJobSource names = do              return ( config, Just commit )      cidPart <- case jobsetCommit of -        Just commit -> (: []) . JobIdTree Nothing . treeId <$> getCommitTree commit +        Just commit -> (: []) . JobIdTree Nothing "" . treeId <$> getCommitTree commit          Nothing -> return []      jobsetJobsEither <- fmap Right $ forM names $ \name ->          case find ((name ==) . jobName) (configJobs config) of @@ -162,7 +162,7 @@ rangeSource base tip = do      jobsets <- forM commits $ \commit -> do          tree <- getCommitTree commit          cmdEvalWith (\ei -> ei -            { eiCurrentIdRev = JobIdTree Nothing (treeId tree) : eiCurrentIdRev ei +            { eiCurrentIdRev = JobIdTree Nothing (treeSubdir tree) (treeId tree) : eiCurrentIdRev ei              }) . evalJobSet [] =<< loadJobSetFromRoot root commit      oneshotJobSource jobsets @@ -185,7 +185,7 @@ watchBranchSource branch = do              jobsets <- forM commits $ \commit -> do                  tree <- getCommitTree commit                  let einput = einputBase -                        { eiCurrentIdRev = JobIdTree Nothing (treeId tree) : eiCurrentIdRev einputBase +                        { eiCurrentIdRev = JobIdTree Nothing (treeSubdir tree) (treeId tree) : eiCurrentIdRev einputBase                          }                  either (fail . T.unpack . textEvalError) return =<<                      flip runEval einput . evalJobSet [] =<< loadJobSetFromRoot root commit @@ -215,7 +215,7 @@ watchTagSource pat = do                then do                  tree <- getCommitTree $ tagObject tag                  let einput = einputBase -                        { eiCurrentIdRev = JobIdTree Nothing (treeId tree) : eiCurrentIdRev einputBase +                        { eiCurrentIdRev = JobIdTree Nothing (treeSubdir tree) (treeId tree) : eiCurrentIdRev einputBase                          }                  jobset <- either (fail . T.unpack . textEvalError) return =<<                      flip runEval einput . evalJobSet [] =<< loadJobSetFromRoot root (tagObject tag) |