The options package

[Tags: library, mit]

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:

import Control.Applicative
import Options

data MainOptions = MainOptions
    { optMessage :: String
    , optQuiet :: Bool
    }

instance Options MainOptions where
    defineOptions = pure MainOptions
        <*> simpleOption "message" "Hello world!"
            "A message to show the user."
        <*> simpleOption "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 :: text
    A message to show the user.
    default: "Hello world!"
  --quiet :: bool
    Whether to be quiet.
    default: false

Properties

Versions0.1, 0.1.1, 1.0, 1.1, 1.2
Dependenciesbase (>=4.1 && <5.0), containers (>=0.1), monads-tf (>=0.1), transformers (>=0.2)
LicenseMIT
AuthorJohn Millikin <john@john-millikin.com>
MaintainerJohn Millikin <john@john-millikin.com>
Stabilitystable
CategoryConsole
Home pagehttps://john-millikin.com/software/haskell-options/
Source repositoryhead: git clone https://john-millikin.com/code/haskell-options/
this: git clone https://john-millikin.com/code/haskell-options/(tag haskell-options_1.2)
Upload dateSat May 17 22:47:39 UTC 2014
Uploaded byJohnMillikin
DistributionsDebian:1.2, NixOS:1.2
Downloads1146 total (150 in last 30 days)

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees