class documentation

A parameter to a command comes in two versions: they are either :class:`Option`\s or :class:`Argument`\s. Other subclasses are currently not supported by design as some of the internals for parsing are intentionally not finalized. Some settings are supported by both options and arguments. :param param_decls: the parameter declarations for this option or argument. This is a list of flags or argument names. :param type: the type that should be used. Either a :class:`ParamType` or a Python type. The later is converted into the former automatically if supported. :param required: controls if this is optional or not. :param default: the default value if omitted. This can also be a callable, in which case it's invoked when the default is needed without any arguments. :param callback: A function to further process or validate the value after type conversion. It is called as ``f(ctx, param, value)`` and must return the value. It is called for all sources, including prompts. :param nargs: the number of arguments to match. If not ``1`` the return value is a tuple instead of single value. The default for nargs is ``1`` (except if the type is a tuple, then it's the arity of the tuple). If ``nargs=-1``, all remaining parameters are collected. :param metavar: how the value is represented in the help page. :param expose_value: if this is `True` then the value is passed onwards to the command callback and stored on the context, otherwise it's skipped. :param is_eager: eager values are processed before non eager ones. This should not be set for arguments or it will inverse the order of processing. :param envvar: a string or list of strings that are environment variables that should be checked. :param shell_complete: A function that returns custom shell completions. Used instead of the param's type completion if given. Takes ``ctx, param, incomplete`` and must return a list of :class:`~click.shell_completion.CompletionItem` or a list of strings. .. versionchanged:: 8.0 ``process_value`` validates required parameters and bounded ``nargs``, and invokes the parameter callback before returning the value. This allows the callback to validate prompts. ``full_process_value`` is removed. .. versionchanged:: 8.0 ``autocompletion`` is renamed to ``shell_complete`` and has new semantics described above. The old name is deprecated and will be removed in 8.1, until then it will be wrapped to match the new requirements. .. versionchanged:: 8.0 For ``multiple=True, nargs>1``, the default must be a list of tuples. .. versionchanged:: 8.0 Setting a default is no longer required for ``nargs>1``, it will default to ``None``. ``multiple=True`` or ``nargs=-1`` will default to ``()``. .. versionchanged:: 7.1 Empty environment variables are ignored rather than taking the empty string value. This makes it possible for scripts to clear variables if they can't unset them. .. versionchanged:: 2.0 Changed signature for parameter callback to also be passed the parameter. The old callback format will still work, but it will raise a warning to give you a chance to migrate the code easier.

Method __init__ Undocumented
Method __repr__ Undocumented
Method add_to_parser Undocumented
Method consume_value Undocumented
Method get_default Get the default for the parameter. Tries :meth:`Context.lookup_default` first, then the local default.
Method get_error_hint Get a stringified version of the param for use in error messages to indicate which param caused the error.
Method get_help_record Undocumented
Method get_usage_pieces Undocumented
Method handle_parse_result Undocumented
Method make_metavar Undocumented
Method process_value Undocumented
Method resolve_envvar_value Undocumented
Method shell_complete Return a list of completions for the incomplete value. If a ``shell_complete`` function was given during init, it is used. Otherwise, the :attr:`type` :meth:`~click.types.ParamType.shell_complete` function is used.
Method to_info_dict Gather information that could be useful for a tool generating user-facing documentation.
Method type_cast_value Convert and validate a value against the option's :attr:`type`, :attr:`multiple`, and :attr:`nargs`.
Method value_from_envvar Undocumented
Method value_is_missing Undocumented
Class Variable param_type_name Undocumented
Instance Variable callback Undocumented
Instance Variable default Undocumented
Instance Variable envvar Undocumented
Instance Variable expose_value Undocumented
Instance Variable is_eager Undocumented
Instance Variable metavar Undocumented
Instance Variable multiple Undocumented
Instance Variable name Undocumented
Instance Variable nargs Undocumented
Instance Variable opts Undocumented
Instance Variable required Undocumented
Instance Variable secondary_opts Undocumented
Instance Variable type Undocumented
Property human_readable_name Returns the human readable name of this parameter. This is the same as the name for options, but the metavar for arguments.
Method _parse_decls Undocumented
Instance Variable _custom_shell_complete Undocumented
def __init__(self, param_decls=None, type=None, required=False, default=None, callback=None, nargs=None, multiple=False, metavar=None, expose_value=True, is_eager=False, envvar=None, shell_complete=None): (source)

Undocumented

Parameters
param_decls:t.Optional[t.Sequence[str]]Undocumented
type:t.Optional[t.Union[types.ParamType, t.Any]]Undocumented
required:boolUndocumented
default:t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]Undocumented
callback:t.Optional[t.Callable[[Context, Parameter, t.Any], t.Any]]Undocumented
nargs:t.Optional[int]Undocumented
multiple:boolUndocumented
metavar:t.Optional[str]Undocumented
expose_value:boolUndocumented
is_eager:boolUndocumented
envvar:t.Optional[t.Union[str, t.Sequence[str]]]Undocumented
shell_complete:t.Optional[t.Callable[[Context, Parameter, str], t.Union[t.List[CompletionItem], t.List[str]]]]Undocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def add_to_parser(self, parser, ctx): (source)

Undocumented

Parameters
parser:OptionParserUndocumented
ctx:ContextUndocumented
def consume_value(self, ctx, opts): (source)
overridden in click.core.Option

Undocumented

Parameters
ctx:ContextUndocumented
opts:t.Mapping[str, t.Any]Undocumented
Returns
t.Tuple[t.Any, ParameterSource]Undocumented
def get_default(self, ctx, call=True): (source)
overridden in click.core.Option

Get the default for the parameter. Tries :meth:`Context.lookup_default` first, then the local default. :param ctx: Current context. :param call: If the default is a callable, call it. Disable to return the callable instead. .. versionchanged:: 8.0.2 Type casting is no longer performed when getting a default. .. versionchanged:: 8.0.1 Type casting can fail in resilient parsing mode. Invalid defaults will not prevent showing help text. .. versionchanged:: 8.0 Looks at ``ctx.default_map`` first. .. versionchanged:: 8.0 Added the ``call`` parameter.

Parameters
ctx:ContextUndocumented
call:boolUndocumented
Returns
t.Optional[t.Union[t.Any, t.Callable[[], t.Any]]]Undocumented
def get_error_hint(self, ctx): (source)
overridden in click.core.Argument

Get a stringified version of the param for use in error messages to indicate which param caused the error.

Parameters
ctx:ContextUndocumented
Returns
strUndocumented
def get_help_record(self, ctx): (source)
overridden in click.core.Option

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[t.Tuple[str, str]]Undocumented
def get_usage_pieces(self, ctx): (source)
overridden in click.core.Argument

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.List[str]Undocumented
def handle_parse_result(self, ctx, opts, args): (source)

Undocumented

Parameters
ctx:ContextUndocumented
opts:t.Mapping[str, t.Any]Undocumented
args:t.List[str]Undocumented
Returns
t.Tuple[t.Any, t.List[str]]Undocumented
def make_metavar(self): (source)
overridden in click.core.Argument

Undocumented

Returns
strUndocumented
def process_value(self, ctx, value): (source)

Undocumented

Parameters
ctx:ContextUndocumented
value:t.AnyUndocumented
Returns
t.AnyUndocumented
def resolve_envvar_value(self, ctx): (source)
overridden in click.core.Option

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[str]Undocumented
def shell_complete(self, ctx, incomplete): (source)

Return a list of completions for the incomplete value. If a ``shell_complete`` function was given during init, it is used. Otherwise, the :attr:`type` :meth:`~click.types.ParamType.shell_complete` function is used. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0

Parameters
ctx:ContextUndocumented
incomplete:strUndocumented
Returns
t.List[CompletionItem]Undocumented
def to_info_dict(self): (source)
overridden in click.core.Option

Gather information that could be useful for a tool generating user-facing documentation. Use :meth:`click.Context.to_info_dict` to traverse the entire CLI structure. .. versionadded:: 8.0

Returns
t.Dict[str, t.Any]Undocumented
def type_cast_value(self, ctx, value): (source)

Convert and validate a value against the option's :attr:`type`, :attr:`multiple`, and :attr:`nargs`.

Parameters
ctx:ContextUndocumented
value:t.AnyUndocumented
Returns
t.AnyUndocumented
def value_from_envvar(self, ctx): (source)
overridden in click.core.Option

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.Optional[t.Any]Undocumented
def value_is_missing(self, value): (source)

Undocumented

Parameters
value:t.AnyUndocumented
Returns
boolUndocumented
param_type_name: str = (source)

Undocumented

callback = (source)

Undocumented

default = (source)
overridden in click.core.Option

Undocumented

envvar = (source)

Undocumented

expose_value = (source)

Undocumented

is_eager = (source)

Undocumented

metavar = (source)

Undocumented

multiple = (source)

Undocumented

name = (source)

Undocumented

nargs = (source)

Undocumented

opts = (source)

Undocumented

required = (source)

Undocumented

secondary_opts = (source)

Undocumented

type = (source)
overridden in click.core.Option

Undocumented

@property
human_readable_name: str = (source)
overridden in click.core.Argument

Returns the human readable name of this parameter. This is the same as the name for options, but the metavar for arguments.

def _parse_decls(self, decls, expose_value): (source)

Undocumented

Parameters
decls:t.Sequence[str]Undocumented
expose_value:boolUndocumented
Returns
t.Tuple[t.Optional[str], t.List[str], t.List[str]]Undocumented
_custom_shell_complete = (source)

Undocumented