| Trees | Indices | Help |
|
|---|
|
|
The module contains routines to parse command arguments and map them to the command handler's positonal and keyword arguments.
Mapping is done in two stages: 1) parse arguments into positional arguments and options; 2) adapt them to the specific command handler according to the command properties.
|
|||
|
|||
|
|||
|
|||
|
|||
ARG_PATTERN = re.compile(r'
|
|||
OPT_PATTERN = re.compile(r'
|
|||
KEY_ENCODING =
|
|||
USAGE_PATTERN =
|
|||
Imports: re, BooleanType, UnicodeType, itemgetter, DefinitionError, CommandError
|
|||
Simple yet effective and sufficient in most cases parser which parses command arguments and returns them as two lists. First list represents positional arguments as (argument, position), and second representing options as (key, value, position) tuples, where position is a (start, end) span tuple of where it was found in the string. Options may be given in --long or -short format. As --option=value or --option value or -option value. Keys without values will get None as value. Arguments and option values that contain spaces may be given as 'one two three' or "one two three"; that is between single or double quotes. |
Adapt args and opts got from the parser to a specific handler by means of arguments specified on command definition. That is transform them to *args and **kwargs suitable for passing to a command handler. Dashes (-) in the option names will be converted to underscores. So you can map --one-more-option to a one_more_option=None. If the initial value of a keyword argument is a boolean (False in most cases) - then this option will be treated as a switch, that is an option which does not take an argument. If a switch is followed by an argument - then this argument will be treated just like a normal positional argument. |
|
|
|||
ARG_PATTERN
|
OPT_PATTERN
|
KEY_ENCODING
|
USAGE_PATTERN
|
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Fri Jul 30 02:06:26 2010 | http://epydoc.sourceforge.net |