The options package

[ Tags: console, library, mit ] [ Propose Tags ]

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

Versions 0.1, 0.1.1, 1.0, 1.1, 1.2, 1.2.1, 1.2.1.1
Dependencies base (>=4.1 && <4.8), bytestring (>=0.9), containers (>=0.1), monads-tf (>=0.1), transformers (>=0.2) [details]
License MIT
Author John Millikin <john@john-millikin.com>
Maintainer John Millikin <john@john-millikin.com>
Category Console
Home page https://john-millikin.com/software/haskell-options/
Source repository head: git clone https://john-millikin.com/code/haskell-options/
this: git clone https://john-millikin.com/code/haskell-options/(tag haskell-options_1.0)
Uploaded Sun Mar 2 03:45:24 UTC 2014 by JohnMillikin
Updated Mon Dec 29 11:22:23 UTC 2014 by HerbertValerioRiedel to revision 1   [What is this?]
Distributions Arch:1.2.1.1, Debian:1.2.1.1, LTSHaskell:1.2.1.1, NixOS:1.2.1.1, Stackage:1.2.1.1, Tumbleweed:1.2.1.1
Downloads 5960 total (865 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

For package maintainers and hackage trustees