Descriptive.Options

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

Safe Haskell | Safe
Language | Haskell98

Descriptive.Options

Contents

- Existence flags
- Text input arguments
- Token consumers
- Special control
- Description

Description

Command-line options parser.

Synopsis

- flag :: Monad m => Text -> Text -> v -> Consumer [Text] (Option a) m v
- switch :: Monad m => Text -> Text -> Consumer [Text] (Option a) m Bool
- prefix :: Monad m => Text -> Text -> Consumer [Text] (Option a) m Text
- arg :: Monad m => Text -> Text -> Consumer [Text] (Option a) m Text
- anyString :: Monad m => Text -> Consumer [Text] (Option a) m Text
- constant :: Monad m => Text -> Text -> v -> Consumer [Text] (Option a) m v
- stop :: Monad m => Consumer [Text] (Option a) m a -> Consumer [Text] (Option a) m ()
- data Option a
  - = AnyString !Text
  - | Constant !Text !Text
  - | Flag !Text !Text
  - | Arg !Text !Text
  - | Prefix !Text !Text
  - | Stops
  - | Stopped !a
- textDescription :: Description (Option a) -> Text
- textOpt :: Option a -> Text

# 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) # |
Methods (==) :: Option a -> Option a -> Bool # (/=) :: Option a -> Option a -> Bool #
Show a => Show (Option a) # |
Methods showsPrec :: Int -> Option a -> ShowS # show :: Option a -> String # showList :: [Option a] -> ShowS #

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.