lambda-options-0.1.0.0: A modern command-line parser for Haskell.

Safe HaskellNone
LanguageHaskell2010

Text.LambdaOptions

Synopsis

Documentation

class Parseable a where Source

Class describing parseable values. Much like the Read class.

Methods

parse :: String -> Maybe a Source

Given a String, returns Just a if and only if the entire string can be parsed.

type Keyword = String Source

An option keyword, such as "--help"

NB: In the future, this will become a proper data type that contains a list of aliases and help descriptions.

type OptionCallback m f = (Monad m, GetOpaqueParsers f, WrapCallback m f) Source

The callback to be called for a successfully parsed option.

This function (or value) can have any arity and ultimately returns a value with type Monad m => m ()

Each of the callback's arguments must have a type t which implements Parseable.

Example callbacks:

putStrLn "Option parsed!" :: IO ()
put :: String -> State ()
\n -> liftIO (print n) :: (MonadIO m) => Int -> m ()
\n s f -> lift (print (n, s, f)) :: (MonadTrans m) => Int -> String -> Float -> m IO ()

data Options m a Source

A monad transformer for parsing options.

data OptionsError Source

Contains information about what went wrong during an unsuccessful parse.

Constructors

OptionsError

NB: In the future, there will be more informative constructors.

Instances

addOption :: forall m f. OptionCallback m f => Keyword -> f -> Options m () Source

Adds the following option into the monadic context.

runOptions :: Monad m => Options m a -> [String] -> m (Maybe OptionsError) Source

Tries to parse the supplied options against input arguments. If successful, parsed option callbacks are executed.