soenkehahn/getopt-generics

Create command line interfaces with ease

Haskell

42

151 commits

updated Jan 21, 2023

See the code

README

getopt-generics

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

Contributors

soenkehahn

131 commits

qoelet

11 commits

sol

5 commits

kosmikus

3 commits

soenkehahn/getopt-generics

Create command line interfaces with ease

Haskell

42

151 commits

updated Jan 21, 2023

See the code

README

getopt-generics

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

Contributors

soenkehahn

131 commits

qoelet

11 commits

sol

5 commits

kosmikus

3 commits

Languages

Haskell

100.0%