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 |
Undocumented |
Method | consume |
Undocumented |
Method | get |
Get the default for the parameter. Tries :meth:`Context.lookup_default` first, then the local default. |
Method | get |
Get a stringified version of the param for use in error messages to indicate which param caused the error. |
Method | get |
Undocumented |
Method | get |
Undocumented |
Method | handle |
Undocumented |
Method | make |
Undocumented |
Method | process |
Undocumented |
Method | resolve |
Undocumented |
Method | shell |
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 |
Gather information that could be useful for a tool generating user-facing documentation. |
Method | type |
Convert and validate a value against the option's :attr:`type`, :attr:`multiple`, and :attr:`nargs`. |
Method | value |
Undocumented |
Method | value |
Undocumented |
Class Variable | param |
Undocumented |
Instance Variable | callback |
Undocumented |
Instance Variable | default |
Undocumented |
Instance Variable | envvar |
Undocumented |
Instance Variable | expose |
Undocumented |
Instance Variable | is |
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 |
Undocumented |
Instance Variable | type |
Undocumented |
Property | human |
Returns the human readable name of this parameter. This is the same as the name for options, but the metavar for arguments. |
Method | _parse |
Undocumented |
Instance Variable | _custom |
Undocumented |
click.core.Argument
, click.core.Option
Undocumented
Parameters | |
paramt.Optional[ | Undocumented |
type:t.Optional[ | Undocumented |
required:bool | Undocumented |
default:t.Optional[ | Undocumented |
callback:t.Optional[ | Undocumented |
nargs:t.Optional[ | Undocumented |
multiple:bool | Undocumented |
metavar:t.Optional[ | Undocumented |
exposebool | Undocumented |
isbool | Undocumented |
envvar:t.Optional[ | Undocumented |
shellt.Optional[ | Undocumented |
click.core.Argument
, click.core.Option
Undocumented
Parameters | |
parser:OptionParser | Undocumented |
ctx:Context | Undocumented |
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:Context | Undocumented |
call:bool | Undocumented |
Returns | |
t.Optional[ | Undocumented |
click.core.Option
Undocumented
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Optional[ | Undocumented |
click.core.Option
Undocumented
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Optional[ | Undocumented |
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:Context | Undocumented |
incomplete:str | Undocumented |
Returns | |
t.List[ | Undocumented |
click.core.Option
Undocumented
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Optional[ | Undocumented |
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.
click.core.Argument
, click.core.Option
Undocumented
Parameters | |
decls:t.Sequence[ | Undocumented |
exposebool | Undocumented |
Returns | |
t.Tuple[ | Undocumented |