aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoris2015-08-31 13:56:29 +0200
committerJoris2015-08-31 13:56:29 +0200
commit47cbcb0011861cd1f35aa0a804dd2af0847c49c5 (patch)
tree409fd4c6e6fef0277873f561ff39e3b0aaea4b20 /src
parentc874fdacf0e29b5743cd14de2ecb95fe60ddacca (diff)
Adding a command line option parser working example
Diffstat (limited to 'src')
-rw-r--r--src/CommandLineOptions.hs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/CommandLineOptions.hs b/src/CommandLineOptions.hs
new file mode 100644
index 0000000..2a1f585
--- /dev/null
+++ b/src/CommandLineOptions.hs
@@ -0,0 +1,33 @@
+module CommandLineOptions
+ ( Sample(..)
+ , getOptions
+ ) where
+
+import Options.Applicative
+
+data Sample = Sample
+ { hello :: String
+ , quiet :: Bool
+ }
+
+getOptions :: IO Sample
+getOptions =
+ execParser $ info
+ (helper <*> sample)
+ ( fullDesc
+ <> progDesc "Print a greeting for TARGET"
+ <> header "hello - a test for optparse-applicative"
+ )
+
+sample :: Parser Sample
+sample =
+ Sample
+ <$> strOption
+ ( long "name"
+ <> metavar "TARGET"
+ <> help "Target for the greeting"
+ )
+ <*> switch
+ ( long "quiet"
+ <> help "Whether to be quiet"
+ )