class documentation

class OptionParser:

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).

Parameters
ctxoptionally the ~click.Context where this parser should go with.
Method __init__ 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
Method add​_argument Adds a positional argument named dest to the parser.
Method add​_option No summary
Method parse​_args No summary
Instance Variable ​_args Undocumented
Instance Variable ​_long​_opt Undocumented
Instance Variable ​_opt​_prefixes Undocumented
Instance Variable ​_short​_opt Undocumented
Instance Variable allow​_interspersed​_args Undocumented
Instance Variable ctx Undocumented
Instance Variable ignore​_unknown​_options Undocumented
def __init__(self, ctx=None):

Undocumented

Parameters
ctx:t.Optional[Context]Undocumented
def _get_value_from_state(self, option_name, option, state):

Undocumented

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

Undocumented

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

Undocumented

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

Undocumented

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

Undocumented

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

Undocumented

Parameters
arg:strUndocumented
state:ParsingStateUndocumented
def add_argument(self, obj, dest, nargs=1):

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):

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):
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
_args: t.List[Argument] =

Undocumented

_long_opt: t.Dict[str, Option] =

Undocumented

_opt_prefixes: set[str] =

Undocumented

_short_opt: t.Dict[str, Option] =

Undocumented

allow_interspersed_args =

Undocumented

ctx =

Undocumented

ignore_unknown_options =

Undocumented