Safe Haskell | Safe-Inferred |
---|---|
Language | GHC2021 |
Main module for creating option parsers
Synopsis
- data Parser (s :: Symbol) a = Parser {
- parserHelp :: Help
- parseLexed :: Lexemes -> Either Text (a, Lexemes)
- data Positional
- unitParser :: Parser s ()
- addParserHelp :: Help -> Parser s a -> Parser s a
- setParserHelp :: Help -> Parser s a -> Parser s a
- getOptionNames :: Parser s a -> [Text]
- type Command = "Command"
- coerceParser :: Parser s a -> Parser t a
- parseArgs :: Parser s a -> [Text] -> Either Text a
- parse :: Parser s a -> Text -> Either Text a
- parserOf :: forall a b. (ApplyVariadic (Parser Command) a b, Typeable a, Typeable b) => a -> Typed b
- maybeParser :: Parser s a -> Parser s (Maybe a)
- listParser :: Parser s a -> Parser s [a]
- list1Parser :: Parser s a -> Parser s [a]
- nonEmptyParser :: Parser s a -> Parser s (NonEmpty a)
- parseField :: forall s a. (KnownSymbol s, Typeable a, Show a) => FieldConfiguration -> Positional -> Text -> OptionDescriptionUpdates -> DefaultValue s a -> ActiveValue s a -> Decoder a -> Parser s a
- parseWith :: forall s a. (KnownSymbol s, Typeable a, Show a) => OptionDescriptionUpdates -> DefaultValue s a -> ActiveValue s a -> Decoder a -> Parser s a
- takeOptionValue :: [Text] -> Lexemes -> Maybe (Text, Maybe Text, Lexemes)
- takeArgumentValue :: Lexemes -> Maybe (Text, Lexemes)
- getSymbol :: forall s. KnownSymbol s => Text
- showType :: forall a. Typeable a => Text
Documentation
data Parser (s :: Symbol) a Source #
A Parser is responsible for parsing a value of type a
for to be used as "s" where s is a Symbol
For example "s" can be the name of a field, force
in a data type
A Parser generally returns all the original lexemes values minus the option name and value just parsed This is a bit different for positional arguments for example where the whole list of lexemes values is kept
Parser | |
|
data Positional Source #
This data type indicates if an argument must be parsed at a specific position This changes the parsing since positional arguments do not consume lexemes
Instances
Show Positional Source # | |
Defined in Data.Registry.Options.Parser showsPrec :: Int -> Positional -> ShowS # show :: Positional -> String # showList :: [Positional] -> ShowS # | |
Eq Positional Source # | |
Defined in Data.Registry.Options.Parser (==) :: Positional -> Positional -> Bool # (/=) :: Positional -> Positional -> Bool # |
unitParser :: Parser s () Source #
This parser does not consume anything but always succeeds.
It is a unit for the *>
operator
getOptionNames :: Parser s a -> [Text] Source #
Retrieve all the option names for this parser by extracting the help and collecting option names for the top level command and the subcommands
type Command = "Command" Source #
The Command type can be used to create parsers which are not given a specific role
coerceParser :: Parser s a -> Parser t a Source #
All parsers can be used to parse a command
parseArgs :: Parser s a -> [Text] -> Either Text a Source #
Command line arguments can be parsed with a specific and either return an error if there is nothing to parse, or if the parse is not successful
parse :: Parser s a -> Text -> Either Text a Source #
Shortcut for parsing some text by splitting it on spaces
parserOf :: forall a b. (ApplyVariadic (Parser Command) a b, Typeable a, Typeable b) => a -> Typed b Source #
Create a Parser a for a given constructor of type a by using the Applicative instance of a Parser
maybeParser :: Parser s a -> Parser s (Maybe a) Source #
Make a Parser for a Maybe
type.
If the original parser does not succeeds this parser
returns Nothing
and does not consume anything
listParser :: Parser s a -> Parser s [a] Source #
Make a Parser for a List
type.
This works by repeatedly applying the original parser to
inputs (and appending results) until the parser fails in which case []
is returned
list1Parser :: Parser s a -> Parser s [a] Source #
Make a Parser for a List
type where at least one value is expected to be parsed
nonEmptyParser :: Parser s a -> Parser s (NonEmpty a) Source #
Make a Parser for a NonEmpty
type
(this means that least one value is expected to be parsed)
parseField :: forall s a. (KnownSymbol s, Typeable a, Show a) => FieldConfiguration -> Positional -> Text -> OptionDescriptionUpdates -> DefaultValue s a -> ActiveValue s a -> Decoder a -> Parser s a Source #
Create a Parser for command-line field given: - fieldOptions to derive longshortmetavar names from a field name - a field name. If it is missing, then we can only parse arguments - a field type. We use the type to make a METAVAR - additional OptionDescription to either override the previous values, or to add the field help - an optional default value for the field: the value to use if the field is missing - an optional active value for the field: the value to use if the field is present - a Decoder to read the value as text
parseWith :: forall s a. (KnownSymbol s, Typeable a, Show a) => OptionDescriptionUpdates -> DefaultValue s a -> ActiveValue s a -> Decoder a -> Parser s a Source #
Create a parser for a given field given: - its name(s) - an optional default value for the field: the value to use if the field is missing - an optional active value for the field: the value to use if the field is present - a Decoder to read the value as text
takeOptionValue :: [Text] -> Lexemes -> Maybe (Text, Maybe Text, Lexemes) Source #
Find a value for a given option name return Nothing if the name is not found If the name is found return - Nothing if there is no value - the first value for that name if there is is one and remove the value associated to the flag if there aren't any values left associated to a flag, remove it
takeArgumentValue :: Lexemes -> Maybe (Text, Lexemes) Source #
Take the first argument value available and remove it from the list of lexed arguments
getSymbol :: forall s. KnownSymbol s => Text Source #
Return the textual representation of a symbol (this is a fully qualified string)