parser
¶
-
class
invoke.parser.parser.
ParseResult
(*args, **kwargs)¶ List-like object with some extra parse-related attributes.
Specifically, a
.remainder
attribute, which is the string found after a--
in any parsed argv list; and an.unparsed
attribute, a list of tokens that were unable to be parsed.-
__weakref__
¶ list of weak references to the object (if defined)
-
-
class
invoke.parser.parser.
Parser
(contexts=(), initial=None, ignore_unknown=False)¶ Create parser conscious of
contexts
and optionalinitial
context.contexts
should be an iterable ofContext
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 ofcontexts
. By default it isFalse
, meaning any unknown contexts result in a parse error exception. IfTrue
, encountering an unknown context halts parsing and populates the return value’s.unparsed
attribute with the remaining parse tokens.-
__weakref__
¶ list of weak references to the object (if defined)
-
parse_argv
(argv)¶ Parse an argv-style token list
argv
.Returns a list of
Context
objects matching the order they were found in theargv
and containingArgument
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', ...])
-