mirror of
https://github.com/ilyakooo0/optparse-applicative.git
synced 2024-12-11 06:11:50 +03:00
32 lines
686 B
Haskell
32 lines
686 B
Haskell
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" )
|