class Parser: (source)
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 |
Parse an argv-style token list ``argv``. |
Instance Variable | contexts |
Undocumented |
Instance Variable | ignore |
Undocumented |
Instance Variable | initial |
Undocumented |
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