lambda-options: Declarative command-line parser using type-driven pattern matching.

[ bsd3, library, text ] [ Propose Tags ]

This is a declarative command-line parser that uses type-driven pattern matching.


[Skip to Readme]
Versions [faq] 0.1.0.0, 0.2.0.0, 0.3.0.0, 0.4.0.0, 0.4.0.1, 0.4.0.2, 0.5.0.0, 0.5.1.0, 0.6.0.0, 0.7.0.0, 0.8.0.0, 0.9.0.0, 0.9.0.1, 0.9.1.0, 1.0.0.0, 1.0.1.0, 1.0.2.0, 1.1.0.0
Dependencies base (>=4.12.0.0 && <4.13), containers (>=0.6.0.1 && <0.7), funspection (>=1.0.0.0 && <1.1), mtl (>=2.2.2 && <2.3), read-bounded (>=0.1.1.2 && <0.2) [details]
License BSD-3-Clause
Author Thomas Eding
Maintainer Thomas Eding
Category Text
Home page https://github.com/thomaseding/lambda-options
Bug tracker https://github.com/thomaseding/lambda-options/issues
Uploaded by ThomasEding at Sun Nov 17 00:54:27 UTC 2019
Distributions NixOS:1.1.0.0
Downloads 6496 total (375 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-11-17 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for lambda-options-1.0.2.0

[back to package description]

lambda-options-haskell

Declarative command line parser using type-driven pattern matching.

  • Easy to use. The API is expressive.
  • Easy to learn. The API is tiny and simple.

Homepage: https://github.com/thomaseding/lambda-options

Hackage: https://hackage.haskell.org/package/lambda-options


Basic example:

import qualified System.Environment as IO
import qualified Text.LambdaOptions as L

options :: L.Options (IO ()) ()
options = do

  L.addOption
    (L.kw ["--help", "-h"]
    `L.text` "Display this help text.")
    $ do
      putStrLn "Usage:"
      putStrLn $ L.getHelpDescription options

  L.addOption
    (L.kw "--user"
    `L.argText` "NAME"
    `L.text` "Prints name.")
    $ \name -> do
      putStrLn $ "Name:" ++ name

  L.addOption
    (L.kw "--user"
    `L.argText` "NAME AGE"
    `L.text` "Prints name and age.")
    $ \name age -> do
      putStrLn $ "Name:" ++ name ++ " Age:" ++ show (age :: Int)

main :: IO ()
main = do
  args <- IO.getArgs
  case L.runOptions options args of
    Left e -> do
      putStrLn $ L.prettyOptionsError e
      putStrLn $ L.getHelpDescription options
    Right actions -> sequence_ actions
$ example.exe --user HaskellCurry 81 --user GraceHopper
Name:HaskellCurry Age:81
Name:GraceHopper
$ example.exe -h
Usage:
 -h, --help                  Display this help text.
     --user NAME             Prints name.
     --user NAME AGE         Prints name and age.
$ example.exe --user Pythagoras LXXV
Unknown option at index 2: `LXXV'
Usage:
 -h, --help                  Display this help text.
     --user NAME             Prints name.
     --user NAME AGE         Prints name and age.