optparse-applicative/tests/hello.hs
Paolo Capriotti dfc07b02a6 Add builder for ParserInfo.
Convert `ParserInfo` to use lenses, and add a builder and modifiers to
create a `ParserInfo` object using the same syntax as for options.
2012-05-18 18:29:50 +01:00

31 lines
731 B
Haskell

import Control.Applicative
import Options.Applicative
import Options.Applicative.Builder
import Options.Applicative.Extra
data Sample = Sample
{ hello :: String
, quiet :: Bool }
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 True) = putStrLn $ "Hello, " ++ h
greet _ = return ()
main :: IO ()
main = execParser opts >>= greet
where
opts = info (helper <*> sample)
( fullDesc
& progDesc "Print a greeting for TARGET"
& header "hello - a test for optparse-applicative" )