diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-24 09:37:52 +0200 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-05-24 15:37:08 +0200 |
commit | a5f20f40840a0cbc1580261bff3d3a7fd2cdc29b (patch) | |
tree | 49a26ca92417e1d9151ea2c5508f7dbc46a6e45f | |
parent | 76370492c9c0cdbb51b4f7c14e082c04b0b223d5 (diff) |
Parse parentheses in job reference
-rw-r--r-- | src/Command/Extract.hs | 7 | ||||
-rw-r--r-- | src/Command/JobId.hs | 2 | ||||
-rw-r--r-- | src/Command/Log.hs | 2 | ||||
-rw-r--r-- | src/Job/Types.hs | 14 |
4 files changed, 20 insertions, 5 deletions
diff --git a/src/Command/Extract.hs b/src/Command/Extract.hs index b24a1af..4336b29 100644 --- a/src/Command/Extract.hs +++ b/src/Command/Extract.hs @@ -31,9 +31,10 @@ instance CommandArgumentsType ExtractArguments where extractDestination <- return (last args) return ExtractArguments {..} where - toArtifactRef tref = case T.splitOn "." (T.pack tref) of - parts@(_:_:_) -> return ( JobRef (init parts), ArtifactName (last parts) ) - _ -> throwError $ "too few parts in artifact ref ‘" <> tref <> "’" + toArtifactRef tref = case T.breakOnEnd "." (T.pack tref) of + (jobref', aref) | Just ( jobref, '.' ) <- T.unsnoc jobref' + -> return ( parseJobRef jobref, ArtifactName aref ) + _ -> throwError $ "too few parts in artifact ref ‘" <> tref <> "’" _ -> throwError "too few arguments" data ExtractOptions = ExtractOptions diff --git a/src/Command/JobId.hs b/src/Command/JobId.hs index 1cfd18c..429e2a0 100644 --- a/src/Command/JobId.hs +++ b/src/Command/JobId.hs @@ -44,7 +44,7 @@ instance Command JobIdCommand where "show detals of the ID" ] - commandInit _ opts = JobIdCommand opts . JobRef . T.splitOn "." + commandInit _ opts = JobIdCommand opts . parseJobRef commandExec = cmdJobId diff --git a/src/Command/Log.hs b/src/Command/Log.hs index 92866d4..5d8c9d4 100644 --- a/src/Command/Log.hs +++ b/src/Command/Log.hs @@ -30,7 +30,7 @@ instance Command LogCommand where [ "Usage: minici log <job ref>" ] - commandInit _ _ = LogCommand . JobRef . T.splitOn "." + commandInit _ _ = LogCommand . parseJobRef commandExec = cmdLog diff --git a/src/Job/Types.hs b/src/Job/Types.hs index 7e7a4b8..1ac329e 100644 --- a/src/Job/Types.hs +++ b/src/Job/Types.hs @@ -86,3 +86,17 @@ textJobIdPart = \case textJobId :: JobId -> Text textJobId (JobId ids) = T.intercalate "." $ map textJobIdPart ids + +parseJobRef :: Text -> JobRef +parseJobRef = JobRef . go 0 "" + where + go :: Int -> Text -> Text -> [ Text ] + go plevel cur s = do + let bchars | plevel > 0 = [ '(', ')' ] + | otherwise = [ '.', '(', ')' ] + let ( part, rest ) = T.break (`elem` bchars) s + case T.uncons rest of + Just ( '.', rest' ) -> (cur <> part) : go plevel "" rest' + Just ( '(', rest' ) -> go (plevel + 1) (cur <> part) rest' + Just ( ')', rest' ) -> go (plevel - 1) (cur <> part) rest' + _ -> [ cur <> part ] |