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