Search CmdArgs API

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:

  1. It's very concise to use. The HLint command line handling is three times shorter with CmdArgs.
  2. 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 = Sample{hello = def &= help "World argument" &= opt "world"}
         &= summary "Sample v1"

main = print =<< cmdArgs 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)

Related work

Downloads

Tags: haskell library popular