mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-11-30 23:53:48 +03:00
dfc07b02a6
Convert `ParserInfo` to use lenses, and add a builder and modifiers to create a `ParserInfo` object using the same syntax as for options.
29 lines
655 B
Haskell
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
|