on master help sign in
Port stackage.hs to use optparse-applicative
commit7819eea565ecfa0c4a013038810fa2683618b008 authorChris Done <chrisdone@gmail.com> dateWed 31 Dec 2014, 18:52 (12 years ago) parent1d2d92d
2 files changed+44−13
app/stackage.hs+43−13 stackage.cabal+1
app/stackage.hs+43−13
@@ -1,16 +1,46 @@
1+module Main where
2+
3+import Control.Monad
4+import Data.Monoid
5+import Data.Version
6+import Options.Applicative
7+import Paths_stackage (version)
18import Stackage.CompleteBuild
2−import System.Environment (getArgs)
39
410main :: IO ()
5−main = do
6− args <- getArgs
7− case args of
8− [x] | Just y <- lookup x m -> y
9− _ -> error $ "Expected one argument, one of: " ++ unwords (map fst m)
10− where
11− m =
12− [ ("nightly", completeBuild Nightly)
13− , ("lts-major", completeBuild $ LTS Major)
14− , ("lts-minor", completeBuild $ LTS Minor)
15− , ("check", justCheck)
16− ]
11+main =
12+ join (execParser
13+ (info (helpOption <*> versionOption <*> config)
14+ (header "Stackage" <>
15+ fullDesc)))
16+ where helpOption =
17+ abortOption
18+ ShowHelpText
19+ (long "help" <>
20+ help "Show this help text")
21+ versionOption =
22+ infoOption
23+ ("fpbuild version " ++ showVersion version)
24+ (long "version" <>
25+ help "Show fpbuild version")
26+ config =
27+ subparser (mconcat [cmnd completeBuild
28+ (pure Nightly)
29+ "nightly"
30+ "Build, test and upload the Nightly snapshot"
31+ ,cmnd completeBuild
32+ (pure (LTS Major))
33+ "lts-major"
34+ "Build, test and upload the LTS (major) snapshot"
35+ ,cmnd completeBuild
36+ (pure (LTS Minor))
37+ "lts-minor"
38+ "Build, test and upload the LTS (minor) snapshot"
39+ ,cmnd (const justCheck)
40+ (pure ())
41+ "check"
42+ "Just check that the build plan is ok"])
43+ cmnd exec parse name desc =
44+ (command name
45+ (info (fmap exec parse)
46+ (progDesc desc)))
stackage.cabal+1
@@ -68,6 +68,7 @@ executable stackage
6868 main-is: stackage.hs
6969 build-depends: base
7070 , stackage
71+ , optparse-applicative >= 0.11
7172 ghc-options: -rtsopts -threaded -with-rtsopts=-N
7273
7374test-suite spec