packages feed

optparse-applicative 0.4.1 → 0.4.2

raw patch · 10 files changed

+235/−1 lines, 10 files

Files

optparse-applicative.cabal view
@@ -1,5 +1,5 @@ name:                optparse-applicative-version:             0.4.1+version:             0.4.2 synopsis:            Utilities and combinators for parsing command line options description:     Here is a simple example of an applicative option parser:@@ -70,6 +70,15 @@ build-type:          Simple cabal-version:       >= 1.8 extra-source-files:  README.md+                     tests/Examples/Alternatives.hs+                     tests/Examples/Cabal.hs+                     tests/Examples/Commands.hs+                     tests/Examples/Hello.hs+                     tests/alt.err.txt+                     tests/cabal.err.txt+                     tests/commands.err.txt+                     tests/hello.err.txt+                     tests/nested.err.txt homepage:            https://github.com/pcapriotti/optparse-applicative bug-reports:         https://github.com/pcapriotti/optparse-applicative/issues 
+ tests/Examples/Alternatives.hs view
@@ -0,0 +1,18 @@+module Examples.Alternatives where++import Options.Applicative++data Value = A | B+  deriving (Eq, Show)++values :: Parser [Value]+values = many $ a <|> b++a :: Parser Value+a = flag' A (short 'a')++b :: Parser Value+b = flag' B (short 'b')++opts :: ParserInfo [Value]+opts = info values idm
+ tests/Examples/Cabal.hs view
@@ -0,0 +1,116 @@+{-# LANGUAGE Arrows #-}+module Examples.Cabal where++import Options.Applicative+import Options.Applicative.Arrows++data Args = Args CommonOpts Command+  deriving Show++data CommonOpts = CommonOpts+  { optVerbosity :: Int }+  deriving Show++data Command+  = Install ConfigureOpts InstallOpts+  | Update+  | Configure ConfigureOpts+  | Build BuildOpts+  deriving Show++data InstallOpts = InstallOpts+  { instReinstall :: Bool+  , instForce :: Bool }+  deriving Show++data ConfigureOpts = ConfigureOpts+  { configTests :: Bool+  , configFlags :: [String] }+  deriving Show++data BuildOpts = BuildOpts+  { buildDir :: FilePath }+  deriving Show++parser :: Parser Args+parser = runA $ proc () -> do+  opts <- asA commonOpts -< ()+  cmds <- (asA . subparser)+            ( command "install"+              (info installParser+                    (progDesc "Installs a list of packages"))+            & command "update"+              (info updateParser+                    (progDesc "Updates list of known packages"))+            & command "configure"+              (info configureParser+                    (progDesc "Prepare to build the package"))+            & command "build"+              (info buildParser+                    (progDesc "Make this package ready for installation")) ) -< ()+  A helper -< Args opts cmds++commonOpts :: Parser CommonOpts+commonOpts = CommonOpts+  <$> option+      ( short 'v'+      & long "verbose"+      & metavar "LEVEL"+      & help "Set verbosity to LEVEL"+      & value 0 )++installParser :: Parser Command+installParser = runA $ proc () -> do+  config <- asA configureOpts -< ()+  inst <- asA installOpts -< ()+  A helper -< Install config inst++installOpts :: Parser InstallOpts+installOpts = runA $ proc () -> do+  reinst <- asA (switch (long "reinstall")) -< ()+  force <- asA (switch (long "force-reinstall")) -< ()+  returnA -< InstallOpts+             { instReinstall = reinst+             , instForce = force }++updateParser :: Parser Command+updateParser = runA $ proc () ->+  A helper -< Update++configureParser :: Parser Command+configureParser = runA $ proc () -> do+  config <- asA configureOpts -< ()+  A helper -< Configure config++configureOpts :: Parser ConfigureOpts+configureOpts = runA $ proc () -> do+  tests <- (asA . switch)+             ( long "enable-tests"+             & help "Enable compilation of test suites" ) -< ()+  flags <- (asA . many . strOption)+             ( short 'f'+             & long "flags"+             & metavar "FLAGS"+             & help "Enable the given flag" ) -< ()+  returnA -< ConfigureOpts tests flags++buildParser :: Parser Command+buildParser = runA $ proc () -> do+  opts <- asA buildOpts -< ()+  A helper -< Build opts++buildOpts :: Parser BuildOpts+buildOpts = runA $ proc () -> do+  bdir <- (asA . strOption)+            ( long "builddir"+            & metavar "DIR"+            & value "dist" ) -< ()+  returnA -< BuildOpts bdir++pinfo :: ParserInfo Args+pinfo = info parser idm++main :: IO ()+main = do+  r <- execParser pinfo+  print r
+ tests/Examples/Commands.hs view
@@ -0,0 +1,32 @@+module Examples.Commands where++import Data.List+import Options.Applicative++data Sample+  = Hello [String]+  | Goodbye+  deriving Show++hello :: Parser Sample+hello = Hello <$> arguments str (metavar "TARGET...")++sample :: Parser Sample+sample = subparser+       ( command "hello"+         (info hello+               (progDesc "Print greeting"))+       & command "goodbye"+         (info (pure Goodbye)+               (progDesc "Say goodbye"))+       )++run :: Sample -> IO ()+run (Hello targets) = putStrLn $ "Hello, " ++ intercalate ", " targets ++ "!"+run Goodbye = putStrLn "Goodbye."++opts :: ParserInfo Sample+opts = info sample idm++main :: IO ()+main = execParser opts >>= run
+ tests/Examples/Hello.hs view
@@ -0,0 +1,31 @@+module Examples.Hello where++import Options.Applicative++data Sample = Sample+  { hello :: String+  , quiet :: Bool }+  deriving Show++sample :: Parser Sample+sample = Sample+     <$> strOption+         ( long "hello"+         & metavar "TARGET"+         & help "Target for the greeting" )+     <*> switch+         ( long "quiet"+         & help "Whether to be quiet" )++greet :: Sample -> IO ()+greet (Sample h False) = putStrLn $ "Hello, " ++ h+greet _ = return ()++main :: IO ()+main = execParser opts >>= greet++opts :: ParserInfo Sample+opts = info (sample <**> helper)+  ( fullDesc+  & progDesc "Print a greeting for TARGET"+  & header "hello - a test for optparse-applicative" )
+ tests/alt.err.txt view
@@ -0,0 +1,6 @@+Usage: alt (--virtual-machine VM | --cloud-service CS | --dry-run)++Available options:+  --virtual-machine VM     Virtual machine name+  --cloud-service CS       Cloud service name+  -h,--help                Show this help text
+ tests/cabal.err.txt view
@@ -0,0 +1,7 @@+Usage: cabal configure [--enable-tests] [-f|--flags FLAGS]+  Prepare to build the package++Available options:+  --enable-tests           Enable compilation of test suites+  -f,--flags FLAGS         Enable the given flag+  -h,--help                Show this help text
+ tests/commands.err.txt view
@@ -0,0 +1,5 @@+Usage: commands COMMAND++Available commands:+  hello                    Print greeting+  goodbye                  Say goodbye
+ tests/hello.err.txt view
@@ -0,0 +1,9 @@+hello - a test for optparse-applicative++Usage: hello --hello TARGET [--quiet]+  Print a greeting for TARGET++Available options:+  --hello TARGET           Target for the greeting+  --quiet                  Whether to be quiet+  -h,--help                Show this help text
+ tests/nested.err.txt view
@@ -0,0 +1,1 @@+Usage: nested c b -a A