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

[ bsd2, library, text ] [ Propose Tags ]

Declarative command line parser using type-driven pattern matching.


[Skip to Readme]
Versions 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
Dependencies base (>=4.9 && <5.0), containers (==0.5.*), mtl (==2.2.*), read-bounded (==0.1.*) [details]
License BSD-2-Clause
Author Thomas Eding
Maintainer thomasedingcode@gmail.com
Category Text
Home page https://github.com/thomaseding/lambda-options
Uploaded by ThomasEding at Sat Mar 24 17:25:23 UTC 2018
Distributions NixOS:0.9.1.0
Downloads 2961 total (44 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for lambda-options-0.9.1.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.
  • BSD 1-Clause License -------------- Basic example:
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 @ ParseFailed{})  -> do
            putStrLn $ parseFailedMessage e
            putStrLn $ 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.