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.
31 lines
731 B
Haskell
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" )
|