diff options
Diffstat (limited to 'src/main/frege/buildclient/config/BuildConfig.fr')
-rw-r--r-- | src/main/frege/buildclient/config/BuildConfig.fr | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/main/frege/buildclient/config/BuildConfig.fr b/src/main/frege/buildclient/config/BuildConfig.fr index 603f1a8..7c3290f 100644 --- a/src/main/frege/buildclient/config/BuildConfig.fr +++ b/src/main/frege/buildclient/config/BuildConfig.fr @@ -46,14 +46,30 @@ expectNumber :: ASTValue -> Maybe Int expectNumber (ASTValue.ASTNumber num) = Just num expectNumber _ = Nothing +maybeOr :: a -> Maybe a -> a +maybeOr _ (Just x) = x +maybeOr x Nothing = x -data BuildSource = GitSource {upstream :: String, branch :: Maybe String} + +data ArchiveFormat = Zip +derive Show ArchiveFormat + +data BuildSource = + GitSource {upstream :: String, branch :: Maybe String} + | HttpSource { url::String, format :: ArchiveFormat, archiveRoot :: Maybe String, skipDirs :: Int } derive Show BuildSource findSource :: ASTDirective -> Either String BuildSource findSource (ASTDirective _ [ASTWord "git"] block) = do upstream <- getTypedArg "upstream" "git upstream directive" block expectString return $ GitSource upstream (getArgDirective "branch" block >>= expectString) +findSource (ASTDirective _ [ASTWord "http"] block) = + do + url <- getTypedArg "url" "url" block expectString + format <- getTypedArg "format" "format" block (\x -> toString x >>= parseFormat) + return $ HttpSource url format (getArgDirective "root" block >>= expectString) $ maybeOr 0 (getArgDirective "skipDirs" block >>= expectNumber) + where parseFormat "zip" = Just ArchiveFormat.Zip + parseFormat _ = Nothing findSource (ASTDirective _ [ASTWord name] _) = fail ("Unknown source type " ++ name) findSource _ = fail "Please provide a source type" |