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 [