summaryrefslogtreecommitdiff
path: root/src/main/frege/buildclient/config/BuildConfig.fr
diff options
context:
space:
mode:
authornea <nea@nea.moe>2023-01-24 21:30:39 +0100
committernea <nea@nea.moe>2023-01-24 21:30:39 +0100
commit00b782440054102c405c2001835cc817c1947037 (patch)
treef904a39e81021585605c31f3fc2801e475c56d31 /src/main/frege/buildclient/config/BuildConfig.fr
parent5f74d9f5bc9bf58e1608bd94ad23c79d016e4256 (diff)
downloadbuildclient-00b782440054102c405c2001835cc817c1947037.tar.gz
buildclient-00b782440054102c405c2001835cc817c1947037.tar.bz2
buildclient-00b782440054102c405c2001835cc817c1947037.zip
http downloading
Diffstat (limited to 'src/main/frege/buildclient/config/BuildConfig.fr')
-rw-r--r--src/main/frege/buildclient/config/BuildConfig.fr18
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"