class ParserContext: (source)
Parsing context with knowledge of flags & their format. Generally associated with the core program or a task. When run through a parser, will also hold runtime values filled in by the parser. .. versionadded:: 1.0
Method | __init__ |
Create a new ``ParserContext`` named ``name``, with ``aliases``. |
Method | __repr__ |
Undocumented |
Method | add |
Adds given ``Argument`` (or constructor args for one) to this context. |
Method | flag |
Similar to `help_tuples` but returns flag names only, no helpstrs. |
Method | help |
Return 2-tuple of ``(flag-spec, help-string)`` for given ``flag``. |
Method | help |
Return sorted iterable of help tuples for all member Arguments. |
Method | names |
Undocumented |
Instance Variable | aliases |
Undocumented |
Instance Variable | args |
Undocumented |
Instance Variable | flags |
Undocumented |
Instance Variable | inverse |
Undocumented |
Instance Variable | name |
Undocumented |
Instance Variable | positional |
Undocumented |
Property | as |
This context's arguments' values keyed by their ``.name`` attribute. |
Property | missing |
Undocumented |
Create a new ``ParserContext`` named ``name``, with ``aliases``. ``name`` is optional, and should be a string if given. It's used to tell ParserContext objects apart, and for use in a Parser when determining what chunk of input might belong to a given ParserContext. ``aliases`` is also optional and should be an iterable containing strings. Parsing will honor any aliases when trying to "find" a given context in its input. May give one or more ``args``, which is a quick alternative to calling ``for arg in args: self.add_arg(arg)`` after initialization.
Adds given ``Argument`` (or constructor args for one) to this context. The Argument in question is added to the following dict attributes: * ``args``: "normal" access, i.e. the given names are directly exposed as keys. * ``flags``: "flaglike" access, i.e. the given names are translated into CLI flags, e.g. ``"foo"`` is accessible via ``flags['--foo']``. * ``inverse_flags``: similar to ``flags`` but containing only the "inverse" versions of boolean flags which default to True. This allows the parser to track e.g. ``--no-myflag`` and turn it into a False value for the ``myflag`` Argument. .. versionadded:: 1.0
Similar to `help_tuples` but returns flag names only, no helpstrs. Specifically, all flag names, flattened, in rough order. .. versionadded:: 1.0
Return sorted iterable of help tuples for all member Arguments. Sorts like so: * General sort is alphanumerically * Short flags win over long flags * Arguments with *only* long flags and *no* short flags will come first. * When an Argument has multiple long or short flags, it will sort using the most favorable (lowest alphabetically) candidate. This will result in a help list like so:: --alpha, --zeta # 'alpha' wins --beta -a, --query # short flag wins -b, --argh -c .. versionadded:: 1.0