diff options
| author | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-09 15:21:56 +0100 |
|---|---|---|
| committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-11-09 19:48:02 +0100 |
| commit | 652d3e82208da8a0b1bd052c7284b5904e59d20a (patch) | |
| tree | c14961759ea1684d126f2832cf9177874aa1e82a | |
| parent | f449ef32e31e10b9412e932f0181ccfa4314e728 (diff) | |
Destination type and config section
| -rw-r--r-- | minici.cabal | 1 | ||||
| -rw-r--r-- | src/Config.hs | 15 | ||||
| -rw-r--r-- | src/Destination.hs | 32 |
3 files changed, 48 insertions, 0 deletions
diff --git a/minici.cabal b/minici.cabal index dbc9dc2..e82a3b4 100644 --- a/minici.cabal +++ b/minici.cabal @@ -56,6 +56,7 @@ executable minici Command.Shell Command.Subtree Config + Destination Eval Job Job.Types diff --git a/src/Config.hs b/src/Config.hs index 1b0e046..9c0a79d 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -26,6 +26,7 @@ import System.FilePath import System.FilePath.Glob import System.Process +import Destination import Job.Types import Repo @@ -42,18 +43,21 @@ data JobRoot data Config = Config { configJobs :: [ DeclaredJob ] , configRepos :: [ DeclaredRepo ] + , configDestinations :: [ DeclaredDestination ] } instance Semigroup Config where a <> b = Config { configJobs = configJobs a ++ configJobs b , configRepos = configRepos a ++ configRepos b + , configDestinations = configDestinations a ++ configDestinations b } instance Monoid Config where mempty = Config { configJobs = [] , configRepos = [] + , configDestinations = [] } instance FromYAML Config where @@ -72,6 +76,9 @@ instance FromYAML Config where | [ "repo", name ] <- T.words tag -> do repo <- parseRepo name node return $ config { configRepos = configRepos config ++ [ repo ] } + | [ "destination", name ] <- T.words tag -> do + destination <- parseDestination name node + return $ config { configDestinations = configDestinations config ++ [ destination ] } _ -> return config parseJob :: Text -> Node Pos -> Parser DeclaredJob @@ -145,6 +152,14 @@ parseRepo name node = choice <*> (fmap T.unpack <$> r .:? "path") ] +parseDestination :: Text -> Node Pos -> Parser DeclaredDestination +parseDestination name node = choice + [ flip (withNull "Destination") node $ return $ DeclaredDestination (DestinationName name) Nothing + , flip (withMap "Destination") node $ \r -> DeclaredDestination + <$> pure (DestinationName name) + <*> (r .:? "url") + ] + findConfig :: IO (Maybe FilePath) findConfig = go "." diff --git a/src/Destination.hs b/src/Destination.hs new file mode 100644 index 0000000..f96e88c --- /dev/null +++ b/src/Destination.hs @@ -0,0 +1,32 @@ +module Destination ( + Destination, + DeclaredDestination(..), + DestinationName(..), + + openDestination, +) where + +import Data.Text (Text) +import Data.Text qualified as T + +import System.Directory + + +data Destination + = FilesystemDestination FilePath + +data DeclaredDestination = DeclaredDestination + { destinationName :: DestinationName + , destinationUrl :: Maybe Text + } + + +newtype DestinationName = DestinationName Text + deriving (Eq, Ord, Show) + + +openDestination :: Text -> IO Destination +openDestination url = do + let path = T.unpack url + createDirectoryIfMissing True path + return $ FilesystemDestination path |