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],,,,,,,,,,,,,,
Dependencies base (>= && <4.13), containers (>= && <0.7), funspection (>= && <0.2), mtl (>=2.2.2 && <2.3), read-bounded (>= && <0.2) [details]
License BSD-3-Clause
Author Thomas Eding
Maintainer Thomas Eding
Category Text
Home page
Bug tracker
Uploaded by ThomasEding at Tue Mar 26 17:05:32 UTC 2019
Distributions NixOS:
Downloads 4008 total (148 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2019-03-26 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for lambda-options-

[back to package description]


Declarative command line parser using type-driven pattern matching.

import System.Environment
import Text.LambdaOptions

options :: Options (IO ()) ()
options = do
    addOption (kw ["--help", "-h"] `text` "Display this help text.") $ do
        putStrLn "Usage:"
        putStrLn $ getHelpDescription options
    addOption (kw "--user" `argText` "NAME" `text` "Prints name.") $ \name -> do
        putStrLn $ "Name:" ++ name
    addOption (kw "--user" `argText` "NAME AGE" `text` "Prints name and age.") $ \name age -> do
        putStrLn $ "Name:" ++ name ++ " Age:" ++ show (age :: Int)

main :: IO ()
main = do
    args <- getArgs
    case runOptions options args of
        Left e -> do
            putStrLn $ parseFailedMessage e
            putStrLn $ getHelpDescription options
        Right actions -> sequence_ actions

$ example.exe --user HaskellCurry 81 --user GraceHopper
Name:HaskellCurry Age:81
$ example.exe -h
 -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'
 -h, --help                  Display this help text.
     --user NAME             Prints name.
     --user NAME AGE         Prints name and age.