[Haskell] ANNOUNCE: options, an easy-to-use command-line option parser

John Millikin jmillikin at gmail.com
Sat Mar 24 20:13:53 CET 2012


Hackage: http://hackage.haskell.org/package/options
Home page: https://john-millikin.com/software/haskell-options/
API reference: https://john-millikin.com/software/haskell-options/reference/haskell-options/latest/

The options package lets library and application developers easily
work with command-line options.

The following example is a full program that can accept two options,
--message and --quiet:

----------------------------------------------------------
{-# LANGUAGE TemplateHaskell #-}

import Options

defineOptions "MainOptions" $ do
    stringOption "optMessage" "message" "Hello world!"
        "A message to show the user."
    boolOption "optQuiet" "quiet" False
        "Whether to be quiet."

main :: IO ()
main = runCommand $ \opts args -> do
    if optQuiet opts
        then return ()
        else putStrLn (optMessage opts)
----------------------------------------------------------

----------------------------------------------------------
$ ./hello
Hello world!
$ ./hello --message='ciao mondo'
ciao mondo
$ ./hello --quiet
$
----------------------------------------------------------

In addition, this library will automatically create documentation
options such as --help and --help-all:

----------------------------------------------------------
$ ./hello --help
Help Options:
  -h, --help                  Show option summary.
  --help-all                  Show all help options.

Application Options:
  --message                   A message to show the user.
  --quiet                     Whether to be quiet.
----------------------------------------------------------



More information about the Haskell mailing list