From 64669c18992339fa632bfea0bf13691844252777 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Smr=C5=BE?= Date: Thu, 22 May 2025 21:45:38 +0200 Subject: Extract command Changelog: Added `extract` command to extract artifacts --- minici.cabal | 1 + src/Command/Extract.hs | 105 ++++++++++++++++++++++++++++++++++++++++ src/Main.hs | 2 + test/asset/artifact/minici.yaml | 17 +++++++ test/script/artifact.et | 27 +++++++++++ 5 files changed, 152 insertions(+) create mode 100644 src/Command/Extract.hs create mode 100644 test/asset/artifact/minici.yaml create mode 100644 test/script/artifact.et diff --git a/minici.cabal b/minici.cabal index b7e01e9..4ecf2bc 100644 --- a/minici.cabal +++ b/minici.cabal @@ -49,6 +49,7 @@ executable minici other-modules: Command Command.Checkout + Command.Extract Command.JobId Command.Log Command.Run diff --git a/src/Command/Extract.hs b/src/Command/Extract.hs new file mode 100644 index 0000000..b24a1af --- /dev/null +++ b/src/Command/Extract.hs @@ -0,0 +1,105 @@ +module Command.Extract ( + ExtractCommand, +) where + +import Control.Monad +import Control.Monad.Except +import Control.Monad.IO.Class + +import Data.Text qualified as T + +import System.Console.GetOpt +import System.Directory +import System.FilePath + +import Command +import Eval +import Job.Types + + +data ExtractCommand = ExtractCommand ExtractOptions ExtractArguments + +data ExtractArguments = ExtractArguments + { extractArtifacts :: [ ( JobRef, ArtifactName ) ] + , extractDestination :: FilePath + } + +instance CommandArgumentsType ExtractArguments where + argsFromStrings = \case + args@(_:_:_) -> do + extractArtifacts <- mapM toArtifactRef (init args) + 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 <> "’" + _ -> throwError "too few arguments" + +data ExtractOptions = ExtractOptions + { extractForce :: Bool + } + +instance Command ExtractCommand where + commandName _ = "extract" + commandDescription _ = "Extract artifacts generated by jobs" + + type CommandArguments ExtractCommand = ExtractArguments + + commandUsage _ = T.pack $ unlines $ + [ "Usage: minici jobid [