options

A powerful and easy-to-use command-line option parser.

https://john-millikin.com/software/haskell-options/

Version on this page:1.2.1.1
LTS Haskell 22.13:1.2.1.2
Stackage Nightly 2023-12-26:1.2.1.2
Latest on Hackage:1.2.1.2

See all snapshots options appears in

MIT licensed and maintained by John Millikin
This version can be pinned in stack with:options-1.2.1.1@sha256:b7221c94791371b87cf397152d9aaffc828b84364867b4393090e3447c5533d0,3265

Module documentation for 1.2.1.1

Used by 3 packages in nightly-2017-10-28(full list with versions):

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