Portability | portable |
---|---|
Stability | stable |
Maintainer | Jose Raymundo Cruz (jose.r.cruz01@gmail.com) |
Safe Haskell | Safe-Inferred |
Modules that contains all types and data types created in the library.
- data Flag a = Flag String String [FlagConf a]
- data FlagError
- type FlagData = (FlagDataMap, FlagAliasMap, [GlobalRule])
- type FlagDataMap = Map String (String, [FlagDataConf])
- type FlagAliasMap = Map String String
- type FlagResults = Map String FlagArgument
- data FlagArgument
- type ArgsResults = [String]
- type ParseResults = (FlagResults, ArgsResults)
- type ProcessResults = (FlagResults, ArgsResults)
- type PipelineFunction = (FlagData, FlagResults) -> ([FlagError], FlagResults)
- type GlobalRule = FlagResults -> Maybe String
- type TokenizeResult = Either [FlagError] [Token]
- data ValidationResult
- data FlagConf a
- = FlagConf_Parser (FlagArgument -> Maybe a)
- | FlagConf_DefaultIf (FlagResults -> Maybe a)
- | FlagConf_RequiredIf (FlagResults -> Bool)
- | FlagConf_EmptyValueIs a
- | FlagConf_Alias [String]
- | FlagConf_DefaultOperation OperationToken
- data FlagDataConf
- data OperationToken
- data FlagValueToken
- data Token
- type DefaultOp = Map String OperationToken
Documentation
Data type that represents a defined flag. It contains:
- the name of the flag * help text for the flag * list of configurations for the flags such as type, default values, etc.
Data type for a flag error. It will contain the error message and what kind of error occurred:
- FatalError: an error that the system can't recover from * NonFatalError: an error that does not stop the process
type FlagData = (FlagDataMap, FlagAliasMap, [GlobalRule])Source
Type that represents a collection of all defined flags.
It has three components:
- A flag map: The key is the flag name and the value is the flag data * An alias map: A map that connects any flag alias with it's unique flag name. This is used to convert each flag alias to it's flag name when parsing. * A list of global validation rules
type FlagDataMap = Map String (String, [FlagDataConf])Source
Type that holds a collection of all flags.
It's a map from flag name to flag data. The flag data holds all defined configuration for each flag such as flag type, parser, default, etc.
type FlagAliasMap = Map String StringSource
Type that holds a map from flag alias to flag name.
It is used to identify the corresponding flag given a flag alias. For
example if the user_id flag has two alias, u
and uid
, this map will
have these entries: { uid
=> user_id
, u
=> user_id
}.
type FlagResults = Map String FlagArgumentSource
Type that represents the final result of the parse process.
It maps a flag name to it's value. This value is of type FlagArgument
,
which means that it can be empty or not.
This type is used by the user to get each flag value in the main method by
using the get
method and passing a flag variable.
data FlagArgument Source
Data type that represents an input flag argument.
It's type will vary depending on the user input. For example if the user
calls the program that expects the user_id
flag:
>>>
./runhaskell Program.hs
FlagArgument = FlagMissing "user_id"
>>>
./runhaskell Program.hs --user_id
FlagArgument = FlagValueMissing "user_id"'
>>>
./runhaskell Program.hs --user_id 8
FlagArgument = FlagValue "user_id" "8"
FlagMissing String | argument not provided |
FlagValueMissing String | argument provided but not it's value |
FlagValue String String | argument with value provided |
type ArgsResults = [String]Source
Type that is the list of remaining positional arguments after the parse process is completed. For example:
./runhaskell Program.hs --user_id 8 one two three
ArgsResults
will contain the list ["one", "two", "three"]
type ParseResults = (FlagResults, ArgsResults)Source
Type that holds the FlagResults
and ArgsResults
together.
type ProcessResults = (FlagResults, ArgsResults)Source
Type of the return value of the process
function and it's sub-functions.
type PipelineFunction = (FlagData, FlagResults) -> ([FlagError], FlagResults)Source
Type that represents a pipeline validation/processing function.
It takes a previous state as a parameter and does a set of modifications to this state.
It returns a list of errors (if any error occurred) and a modified state that will be passed in to the next function in the pipeline.
type GlobalRule = FlagResults -> Maybe StringSource
Type that represents a global validation rule for a FlagResults
.
It is used to create global validation after the flags are processed. If
the result is a Nothing
then the rule passed. Otherwise if a
is returned then the ruled failed with the message "Just
err'err
".
type TokenizeResult = Either [FlagError] [Token]Source
Type that represents the result of the tokenize
function and it's
sub-functions.
It returns either a list of errors or a valid list of tokens.
data ValidationResult Source
Type that specifies whether a given validation was successful or not.
If it was not successful it contains a FlagError
that explains what
failed.
Data type that represent a flag configuration.
It is used when a flag is created to set the type of the flag, how it is parsed, if the flag is required or optional, etc.
FlagConf_Parser (FlagArgument -> Maybe a) | Function that parses the input value of the flag to it's
corresponding type, see The flag input text is of type The function returns a 'Maybe a' type,
|
FlagConf_DefaultIf (FlagResults -> Maybe a) | Function that sets a dependent default value to the flag. If the flag was not provided by the user this will be the default
value for the flag if the default value getter function returns
|
FlagConf_RequiredIf (FlagResults -> Bool) | Function that given a If this function returns true then the flag will be required, and if
not present a If this function returns false then the flag presence will be ignored. |
FlagConf_EmptyValueIs a | Default value for the flag when the flag was provided by the user
but not the flag value ( In this example |
FlagConf_Alias [String] | Alias for the flags. Allows the user to specify multiple names for the same flag, such as short name or synonyms. |
FlagConf_DefaultOperation OperationToken | Default operation for flag when no operation is specified.
|
data FlagDataConf Source
Data type that represents a generic flag type configuration.
It is mapped from the FlagConf
of each flag so that it can be bundled
together with all other flag's data. It is used at the validation/parsing
phase of the process
method to verify that the input flag value is
valid for each flag (i.e. if a required flag was not provided by the user
but this flag has a default value then an error does not occur).
It has a direct mapping of each FlagData
to a non-generic version.
FlagDataConf_Validator (FlagArgument -> Bool) | Determines if a flag value is valid for a given flag. Corresponds to |
FlagDataConf_HasDefault (FlagResults -> Bool) | Determines if a flag has a dependent default value configured. Corresponds just to the predicate part of |
FlagDataConf_RequiredIf (FlagResults -> Bool) | Exactly the same as |
FlagDataConf_HasEmptyValue | Determines if a flag has a It is mapped from an |
FlagDataConf_Alias [String] | Exactly the same as |
FlagDataConf_DefaultOperation OperationToken | Exactly the same as |
data OperationToken Source
Data types for the flag operations
data FlagValueToken Source
Data type that represents the value for a flag when parsed from the input stream.
Data type that represents a flag stream using tokens.
FlagToken String OperationToken FlagValueToken | Token for a flag. Contains name, operation and value. |
ArgToken String | Token for a positional argument. Contains the value of the argument. |
type DefaultOp = Map String OperationTokenSource
Type that contains a map from flag name to default flag operation.