class documentation

class Parser: (source)

View In Hierarchy

Create parser conscious of ``contexts`` and optional ``initial`` context. ``contexts`` should be an iterable of ``Context`` instances which will be searched when new context names are encountered during a parse. These Contexts determine what flags may follow them, as well as whether given flags take values. ``initial`` is optional and will be used to determine validity of "core" options/flags at the start of the parse run, if any are encountered. ``ignore_unknown`` determines what to do when contexts are found which do not map to any members of ``contexts``. By default it is ``False``, meaning any unknown contexts result in a parse error exception. If ``True``, encountering an unknown context halts parsing and populates the return value's ``.unparsed`` attribute with the remaining parse tokens. .. versionadded:: 1.0

Method __init__ Undocumented
Method parse_argv Parse an argv-style token list ``argv``.
Instance Variable contexts Undocumented
Instance Variable ignore_unknown Undocumented
Instance Variable initial Undocumented
def __init__(self, contexts=(), initial=None, ignore_unknown=False): (source)

Undocumented

def parse_argv(self, argv): (source)

Parse an argv-style token list ``argv``. Returns a list (actually a subclass, `.ParseResult`) of `.ParserContext` objects matching the order they were found in the ``argv`` and containing `.Argument` objects with updated values based on any flags given. Assumes any program name has already been stripped out. Good:: Parser(...).parse_argv(['--core-opt', 'task', '--task-opt']) Bad:: Parser(...).parse_argv(['invoke', '--core-opt', ...]) :param argv: List of argument string tokens. :returns: A `.ParseResult` (a ``list`` subclass containing some number of `.ParserContext` objects). .. versionadded:: 1.0

contexts = (source)

Undocumented

ignore_unknown = (source)

Undocumented

Undocumented