on 1efddca help sign in
stackage/app/stackage.hs
68 lines 2.8 kB history raw
1{-# LANGUAGE RecordWildCards #-}
2import Stackage.Types
3import Stackage.Build (build, defaultBuildSettings)
4import Stackage.Init (stackageInit)
5import Stackage.Util (allowPermissive)
6import System.Environment (getArgs, getProgName)
7import Data.Set (fromList)
8import System.IO (hFlush, stdout)
10data BuildArgs = BuildArgs
11 { noClean :: Bool
12 , excluded :: [String]
13 , noPlatform :: Bool
14 , onlyPermissive :: Bool
15 , allowed :: [String]
16 }
18parseBuildArgs :: [String] -> IO BuildArgs
19parseBuildArgs =
20 loop BuildArgs
21 { noClean = False
22 , excluded = []
23 , noPlatform = False
24 , onlyPermissive = False
25 , allowed = []
26 }
27 where
28 loop x [] = return x
29 loop x ("--no-clean":rest) = loop x { noClean = True } rest
30 loop x ("--exclude":y:rest) = loop x { excluded = y : excluded x } rest
31 loop x ("--no-platform":rest) = loop x { noPlatform = True } rest
32 loop x ("--only-permissive":rest) = loop x { onlyPermissive = True } rest
33 loop x ("--allow":y:rest) = loop x { allowed = y : allowed x } rest
34 loop _ (y:_) = error $ "Did not understand argument: " ++ y
36main :: IO ()
37main = do
38 args <- getArgs
39 case args of
40 "build":rest -> do
41 BuildArgs {..} <- parseBuildArgs rest
42 build defaultBuildSettings
43 { cleanBeforeBuild = not noClean
44 , excludedPackages = fromList $ map PackageName excluded
45 , requireHaskellPlatform = not noPlatform
46 , allowedPackage =
47 if onlyPermissive
48 then allowPermissive allowed
49 else const $ Right ()
50 }
51 ["init"] -> do
52 putStrLn "Note: init isn't really ready for prime time use."
53 putStrLn "Using it may make it impossible to build stackage."
54 putStr "Are you sure you want continue (y/n)? "
55 hFlush stdout
56 x <- getLine
57 case x of
58 c:_ | c `elem` "yY" -> stackageInit
59 _ -> putStrLn "Probably a good decision, exiting."
60 ["update"] -> stackageInit >> error "FIXME update"
61 _ -> do
62 pn <- getProgName
63 putStrLn $ "Usage: " ++ pn ++ " <command>"
64 putStrLn "Available commands:"
65 putStrLn " update Download updated Stackage databases. Automatically calls init."
66 putStrLn " init Initialize your cabal file to use Stackage"
67 putStrLn " build [--no-clean] [--no-platform] [--exclude package...] [--only-permissive] [--allow package]"
68 putStrLn " Build the package databases (maintainers only)"