blob: 999771f558364f0e0cdaca40023e576f9ba2d6eb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
{-# LANGUAGE RecordWildCards #-}
--------------------------------------------------------------------------------
module Main where
--------------------------------------------------------------------------------
import Options.Applicative
import Data.Semigroup ((<>))
import qualified System.Environment as Env
--------------------------------------------------------------------------------
data CommandArgs = CommandArgs
{ hello :: String
, quiet :: Bool
, enthusiasm :: Int
} deriving (Eq, Show)
parseArgs :: Parser CommandArgs
parseArgs =
CommandArgs <$> strOption
( long "hello"
<> metavar "TARGET"
<> help "Target for the greeting" )
<*> switch
( long "quiet"
<> short 'q'
<> help "Whether to be quiet" )
<*> option auto
( long "enthusiasm"
<> help "How enthusiastic to greet"
<> showDefault
<> value 1
<> metavar "INT" )
main :: IO ()
main = do
args <- execParser opts
greet args
where
opts = info (parseArgs <**> helper)
( fullDesc
<> progDesc "Print a greeting for TARGET"
<> header "header - a test for optparse-applicative" )
greet :: CommandArgs -> IO ()
greet CommandArgs{..} = putStrLn $ "Hello, " ++ hello ++ replicate enthusiasm '!'
|