Skip to content
Create command line interfaces with ease
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs
src
test
.ghci
.gitignore
.travis.yml
LICENSE
README.md
Setup.hs cabal and travis tweaks Mar 21, 2015
buildDocs.hs
getopt-generics.cabal
package.yaml
stack-ghc-7.10.yaml migrate to stack May 1, 2017
stack-ghc-7.8.yaml
stack-ghc-8.0.yaml
stack-ghc-8.2.yaml update supported stack snapshots Oct 28, 2018
stack-ghc-8.6.yaml
stack.yaml

README.md

getopt-generics

Status

This library is experimental.

Usage

getopt-generics tries to make it very simple to create command line interfaces. Here's an example:

import WithCli

main :: IO ()
main = withCli run

run :: String -> Int -> Bool -> IO ()
run s i b = print (s, i, b)

This is how the program behaves in a shell:

$ program foo 42 true
("foo",42,True)
$ program --help
program [OPTIONS] STRING INTEGER BOOL
  -h  --help  show help and exit
$ program foo 42 bar
cannot parse as BOOL: bar
# exit-code 1
$ program
missing argument of type STRING
missing argument of type INTEGER
missing argument of type BOOL
# exit-code 1
$ program foo 42 yes bar
unknown argument: bar
# exit-code 1
You can’t perform that action at this time.