descriptive-0.7.0: Self-describing consumers/parsers; forms, cmd-line args, JSON, etc.

Safe HaskellSafe-Inferred
LanguageHaskell98

Descriptive.Options

Contents

Description

Command-line options parser.

Synopsis

Existence flags

flag

Arguments

:: Monad m 
=> Text

Name.

-> Text

Description.

-> v

Value returned when present.

-> Consumer [Text] (Option a) m v 

Find a value flag which must succeed. Removes it from the argument list if it succeeds.

switch

Arguments

:: Monad m 
=> Text

Name.

-> Text

Description.

-> Consumer [Text] (Option a) m Bool 

Find a boolean flag. Always succeeds. Omission counts as False. Removes it from the argument list if it returns True.

Text input arguments

prefix

Arguments

:: Monad m 
=> Text

Prefix string.

-> Text

Description.

-> Consumer [Text] (Option a) m Text 

Find an argument prefixed by -X. Removes it from the argument list when it succeeds.

arg

Arguments

:: Monad m 
=> Text

Name.

-> Text

Description.

-> Consumer [Text] (Option a) m Text 

Find a named argument e.g. --name value. Removes it from the argument list when it succeeds.

Token consumers

anyString :: Monad m => Text -> Consumer [Text] (Option a) m Text

Consume one argument from the argument list and pops it from the start of the list.

constant

Arguments

:: Monad m 
=> Text

String.

-> Text

Description.

-> v 
-> Consumer [Text] (Option a) m v 

Consume one argument from the argument list which must match the given string, and also pops it off the argument list.

Special control

stop

Arguments

:: Monad m 
=> Consumer [Text] (Option a) m a

A parser which, when it succeeds, causes the whole parser to stop.

-> Consumer [Text] (Option a) m () 

If the consumer succeeds, stops the whole parser and returns Stopped immediately.

Description

data Option a

Description of a commandline option.

Constructors

AnyString !Text 
Constant !Text !Text 
Flag !Text !Text 
Arg !Text !Text 
Prefix !Text !Text 
Stops 
Stopped !a 

Instances

Eq a => Eq (Option a) 
Show a => Show (Option a) 

textDescription :: Description (Option a) -> Text

Make a text description of the command line options.

textOpt :: Option a -> Text

Make a text description of an option.