CmdArgs
CmdArgs is a Haskell library for defining command line parsers. The two features that make it a better choice than the standard getopt library are:
- It's very concise to use. The HLint command line handling is three times shorter with CmdArgs.
- It supports programs with multiple modes, such as darcs or Cabal.
A very simple example of a command line processor is:
data Sample = Sample {hello :: String}
deriving (Show, Data, Typeable)
sample = mode $ Sample{hello = def &= text "World argument" & empty "world"}
main = print =<< cmdArgs "Sample v1, (C) Neil Mitchell 2009" [sample]
Despite being very concise, this processor is already fairly well featured:
$ runhaskell Sample.hs --hello=world
Sample {hello = "world"}
$ runhaskell Sample.hs --help
Sample v1, (C) Neil Mitchell 2009
sample [FLAG]
-? --help[=FORMAT] Show usage information (optional format)
-V --version Show version information
-v --verbose Higher verbosity
-q --quiet Lower verbosity
-h --hello=VALUE World argument (default=world)