option package:turtle

Transform a parser to a succeed with an empty value instead of failing See also: optional
>>> match (option "1" <> "2") "12"
["12"]

>>> match (option "1" <> "2") "2"
["2"]
One or none. It is useful for modelling any computation that is allowed to fail.

Examples

Using the Alternative instance of Control.Monad.Except, the following functions:
>>> import Control.Monad.Except
>>> canFail = throwError "it failed" :: Except String Int

>>> final = return 42                :: Except String Int
Can be combined by allowing the first function to fail:
>>> runExcept $ canFail *> final
Left "it failed"

>>> runExcept $ optional canFail *> final
Right 42
Parse the given options from the command line
Parse the given options from the command line and add additional information Extended version of options with program version header and footer information
Example usage of this module:
-- options.hs

{-# LANGUAGE OverloadedStrings #-}

import Turtle

parser :: Parser (Text, Int)
parser = (,) <$> optText "name" 'n' "Your first name"
<*> optInt  "age"  'a' "Your current age"

main = do
(name, age) <- options "Greeting script" parser
echo (repr (format ("Hello there, "%s) name))
echo (repr (format ("You are "%d%" years old") age))
$ ./options --name John --age 42
Hello there, John
You are 42 years old
$ ./options --help
Greeting script

Usage: options (-n|--name NAME) (-a|--age AGE)

Available options:
-h,--help                Show this help text
--name NAME              Your first name
--age AGE                Your current age
See the Turtle.Tutorial module which contains more examples on how to use command-line parsing.