class documentation

class OptionParser: (source)

View In Hierarchy

The option parser is an internal class that is ultimately used to parse options and arguments. It's modelled after optparse and brings a similar but vastly simplified API. It should generally not be used directly as the high level Click classes wrap it for you. It's not nearly as extensible as optparse or argparse as it does not implement features that are implemented on a higher level (such as types or defaults). :param ctx: optionally the :class:`~click.Context` where this parser should go with.

Method __init__ Undocumented
Method add_argument Adds a positional argument named `dest` to the parser.
Method add_option Adds a new option named `dest` to the parser. The destination is not inferred (unlike with optparse) and needs to be explicitly provided. Action can be any of ``store``, ``store_const``, ``append``, ``append_const`` or ``count``.
Method parse_args Parses positional arguments and returns ``(values, args, order)`` for the parsed options and arguments as well as the leftover arguments if there are any. The order is a list of objects as they appear on the command line...
Instance Variable allow_interspersed_args Undocumented
Instance Variable ctx Undocumented
Instance Variable ignore_unknown_options Undocumented
Method _get_value_from_state Undocumented
Method _match_long_opt Undocumented
Method _match_short_opt Undocumented
Method _process_args_for_args Undocumented
Method _process_args_for_options Undocumented
Method _process_opts Undocumented
Instance Variable _args Undocumented
Instance Variable _long_opt Undocumented
Instance Variable _opt_prefixes Undocumented
Instance Variable _short_opt Undocumented
def __init__(self, ctx=None): (source)

Undocumented

Parameters
ctx:t.Optional[Context]Undocumented
def add_argument(self, obj, dest, nargs=1): (source)

Adds a positional argument named `dest` to the parser. The `obj` can be used to identify the option in the order list that is returned from the parser.

Parameters
obj:CoreArgumentUndocumented
dest:t.Optional[str]Undocumented
nargs:intUndocumented
def add_option(self, obj, opts, dest, action=None, nargs=1, const=None): (source)

Adds a new option named `dest` to the parser. The destination is not inferred (unlike with optparse) and needs to be explicitly provided. Action can be any of ``store``, ``store_const``, ``append``, ``append_const`` or ``count``. The `obj` can be used to identify the option in the order list that is returned from the parser.

Parameters
obj:CoreOptionUndocumented
opts:t.Sequence[str]Undocumented
dest:t.Optional[str]Undocumented
action:t.Optional[str]Undocumented
nargs:intUndocumented
const:t.Optional[t.Any]Undocumented
def parse_args(self, args): (source)

Parses positional arguments and returns ``(values, args, order)`` for the parsed options and arguments as well as the leftover arguments if there are any. The order is a list of objects as they appear on the command line. If arguments appear multiple times they will be memorized multiple times as well.

Parameters
args:t.List[str]Undocumented
Returns
t.Tuple[t.Dict[str, t.Any], t.List[str], t.List[CoreParameter]]Undocumented
allow_interspersed_args = (source)

Undocumented

Undocumented

ignore_unknown_options = (source)

Undocumented

def _get_value_from_state(self, option_name, option, state): (source)

Undocumented

Parameters
option_name:strUndocumented
option:OptionUndocumented
state:ParsingStateUndocumented
Returns
t.AnyUndocumented
def _match_long_opt(self, opt, explicit_value, state): (source)

Undocumented

Parameters
opt:strUndocumented
explicit_value:t.Optional[str]Undocumented
state:ParsingStateUndocumented
def _match_short_opt(self, arg, state): (source)

Undocumented

Parameters
arg:strUndocumented
state:ParsingStateUndocumented
def _process_args_for_args(self, state): (source)

Undocumented

Parameters
state:ParsingStateUndocumented
def _process_args_for_options(self, state): (source)

Undocumented

Parameters
state:ParsingStateUndocumented
def _process_opts(self, arg, state): (source)

Undocumented

Parameters
arg:strUndocumented
state:ParsingStateUndocumented

Undocumented

_long_opt: t.Dict[str, Option] = (source)

Undocumented

_opt_prefixes: set[str] = (source)

Undocumented

_short_opt: t.Dict[str, Option] = (source)

Undocumented