optparse-applicative/tests/modes.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

29 lines
655 B
Haskell

import Control.Applicative
import Options.Applicative
import Options.Applicative.Builder
import Options.Applicative.Extra
data Sample
= Hello String
| Goodbye
hello :: Parser Sample
hello = Hello <$> argument 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 target) = putStrLn $ "Hello, " ++ target ++ "!"
run Goodbye = putStrLn "Goodbye."
main :: IO ()
main = execParser (info sample idm) >>= run