Module lyntin.argparser
This provides the ArgumentParser class which parses command
arguments automatically into a dictionary as well as a series of
Parser classes which handle single arguments and TypeCheckers which
handle validating user input values and converting them into other types
(string -> int...).
It's very complex, however, it allows us to nicely centralize a lot of
the duties involved in parsing user input into one place rather than
doing it in every single command over and over again. This way commands
can specify their syntax line and the ArgParser handles the rest
returning to the commands a dict with the name/value pairs including
argument defaults.
When building an arg spec, you can pass into the ArgumentParser
several options which change the way it parses the user input.
Supported options:
stripBraces (default=on): whether all arguments should have
braces stripped before being parsed
noparsing (default=off): doesn't insure that all arguments are
parsed. works well when matched with limitparsing=0 to
provide a syntax line for commands that parse their own
input
limitparsing:int (default=-1): only parse this number of tokens
into dict, the rest of the input line goes into
argdict["input"]
nodefaults:bool (default=off): turn off default lookups through variables.
Refer to the modules.lyntincmds and modules.tintincmds for examples on
arg specs and commands and how it all intertwines.
| Classes |
ArgumentParser |
This is the actual ArgumentParser class. |
BooleanChecker |
Accept only boolean values using the utils.convert_boolean
function. |
BooleanOrNoneChecker |
Accept only boolean values or special "not specified"
values. |
ChoiceChecker |
Allows for a value to come from a selection of different strings. |
EvalChecker |
Evaluate its input argument as python code and return the resulting
object. |
ExtraIndexParser |
This class captures the parsing behaviour for an index collector. |
ExtraNamedParser |
This class captures the parsing behaviour for a named value
collector. |
IntChecker |
Accept only integer values and return integer objects. |
Parser |
This is the base class for the parsers that argumentparser uses to
actually populate the dictionary with each argument. |
ReChecker |
Compiles the incoming argument as a regular expression. |
StringChecker |
Essentiallly the same as the trivial base class, but it's explicit
that we just return the string we take in without any transformation. |
TimeChecker |
Accepts a date specification. |
TimeSpanChecker |
Accepts an amount of time and converts it to a number of seconds. |
TypeChecker |
Trivial base class for argument checkers |
defaultOptions
-
- Type:
-
dict
- Value:
{'stripBraces': 1, 'nodefaults': 0, 'noparsing': 0, 'limitparsing': -1\
}
|
|
optionParser
-
- Type:
-
NoneType
- Value:
|
typecheckers
-
- Type:
-
dict
- Value:
{'boolean': <class lyntin.argparser.BooleanChecker at 0x4023732c>,
'booleanornone': <class lyntin.argparser.BooleanOrNoneChecker at 0x40\
23735c>,
'choice': <class lyntin.argparser.ChoiceChecker at 0x4023741c>,
'eval': <class lyntin.argparser.EvalChecker at 0x4023738c>,
'int': <class lyntin.argparser.IntChecker at 0x402372fc>,
're': <class lyntin.argparser.ReChecker at 0x4023744c>,
'string': <class lyntin.argparser.StringChecker at 0x402372cc>,
...
|
|