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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain]

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


[Skip to ReadMe]

Properties

Versions0.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.0.0
Change logNone available
Dependenciesbase (>=4.12.0.0 && <4.13), containers (>=0.6.0.1 && <0.7), funspection (>=0.1.0.0 && <0.2), mtl (>=2.2.2 && <2.3), read-bounded (>=0.1.1.2 && <0.2) [details]
LicenseBSD-3-Clause
AuthorThomas Eding
MaintainerThomas Eding
CategoryText
Home pagehttps://github.com/thomaseding/lambda-options
Bug trackerhttps://github.com/thomaseding/lambda-options/issues
UploadedTue Mar 26 17:04:53 UTC 2019 by ThomasEding

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees


Readme for lambda-options-1.0.0.0

[back to package description]

lambda-options-haskell

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
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.