Undocumented
Function | pass_meta_key |
Create a decorator that passes a key from click.Context.meta as the first argument to the decorated function. |
Constant | F |
Undocumented |
Constant | FC |
Undocumented |
Function | _make_command |
Undocumented |
Function | _param_memo |
Undocumented |
Function | argument |
No summary |
Function | command |
Creates a new Command and uses the decorated function as callback. This will also automatically attach all decorated option s and argument s as parameters to the command. |
Function | confirmation_option |
Add a --yes option which shows a prompt before continuing if not passed. If the prompt is declined, the program will exit. |
Function | group |
Creates a new Group with a function as callback. This works otherwise the same as command just that the cls parameter is set to Group . |
Function | help_option |
Add a --help option which immediately prints the help page and exits the program. |
Function | make_pass_decorator |
No summary |
Function | option |
No summary |
Function | pass_context |
Marks a callback as wanting to receive the current context object as first argument. |
Function | pass_obj |
Similar to pass_context , but only pass the object on the context onwards (Context.obj ). This is useful if that object represents the state of a nested system. |
Function | password_option |
Add a --password option which prompts for a password, hiding input and asking to enter the value again for confirmation. |
Function | version_option |
Add a --version option which immediately prints the version number and exits the program. |
Create a decorator that passes a key from
click.Context.meta
as the first argument to the decorated
function.
Parameters | |
key:str | Key in Context.meta to pass. |
doc_description:t.Optional[ | Description of the object being passed, inserted into the decorator's docstring. Defaults to "the 'key' key from Context.meta". |
Returns | |
t.Callable[ | Undocumented |
Argument
; all keyword
arguments are forwarded unchanged (except cls).
This is equivalent to creating an Argument
instance manually
and attaching it to the Command.params
list.Parameters | |
*param_decls:str | Undocumented |
**attrs:t.Any | Undocumented |
cls | the argument class to instantiate. This defaults to
Argument . |
Returns | |
t.Callable[ | Undocumented |
Creates a new Command
and uses the decorated function as
callback. This will also automatically attach all decorated
option
s and argument
s as parameters to the command.
The name of the command defaults to the name of the function with underscores replaced by dashes. If you want to change that, you can pass the intended name as the first argument.
All keyword arguments are forwarded to the underlying command class.
Once decorated the function turns into a Command
instance
that can be invoked as a command line utility or be attached to a
command Group
.
Parameters | |
name:t.Optional[ | the name of the command. This defaults to the function name with underscores replaced by dashes. |
cls:t.Optional[ | the command class to instantiate. This defaults to
Command . |
**attrs:t.Any | Undocumented |
Returns | |
t.Callable[ | Undocumented |
Parameters | |
*param_decls:str | One or more option names. Defaults to the single value "--yes". |
**kwargs:t.Any | Extra arguments are passed to option . |
Returns | |
t.Callable[ | Undocumented |
Add a --help option which immediately prints the help page and exits the program.
This is usually unnecessary, as the --help option is added to each command automatically unless add_help_option=False is passed.
Parameters | |
*param_decls:str | One or more option names. Defaults to the single value "--help". |
**kwargs:t.Any | Extra arguments are passed to option . |
Returns | |
t.Callable[ | Undocumented |
Given an object type this creates a decorator that will work
similar to pass_obj
but instead of passing the object of the
current context, it will find the innermost context of type
object_type
.
This generates a decorator that works roughly like this:
from functools import update_wrapper def decorator(f): @pass_context def new_func(ctx, *args, **kwargs): obj = ctx.find_object(object_type) return ctx.invoke(f, obj, *args, **kwargs) return update_wrapper(new_func, f) return decorator
Parameters | |
object_type:t.Type | the type of the object to pass. |
ensure:bool | if set to True , a new object will be created and
remembered on the context if it's not there yet. |
Returns | |
t.Callable[ | Undocumented |
Option
; all keyword
arguments are forwarded unchanged (except cls).
This is equivalent to creating an Option
instance manually
and attaching it to the Command.params
list.Parameters | |
*param_decls:str | Undocumented |
**attrs:t.Any | Undocumented |
cls | the option class to instantiate. This defaults to
Option . |
Returns | |
t.Callable[ | Undocumented |
pass_context
, but only pass the object on the
context onwards (Context.obj
). This is useful if that object
represents the state of a nested system.Parameters | |
f:F | Undocumented |
Returns | |
F | Undocumented |
Parameters | |
*param_decls:str | One or more option names. Defaults to the single value "--password". |
**kwargs:t.Any | Extra arguments are passed to option . |
Returns | |
t.Callable[ | Undocumented |
Add a --version option which immediately prints the version number and exits the program.
If version is not provided, Click will try to detect it using
importlib.metadata.version
to get the version for the
package_name. On Python < 3.8, the importlib_metadata
backport must be installed.
If package_name is not provided, Click will try to detect it by inspecting the stack frames. This will be used to detect the version, so it must match the name of the installed package.
importlib.metadata
instead of pkg_resources. The
version is detected based on the package name, not the entry
point name. The Python package name must match the installed
package name, or be passed with package_name=.Parameters | |
version:t.Optional[ | The version number to show. If not provided, Click will try to detect it. |
*param_decls:str | One or more option names. Defaults to the single value "--version". |
package_name:t.Optional[ | The package name to detect the version from. If not provided, Click will try to detect it. |
prog_name:t.Optional[ | The name of the CLI to show in the message. If not provided, it will be detected from the command. |
message:t.Optional[ | The message to show. The values %(prog)s, %(package)s, and %(version)s are available. Defaults to "%(prog)s, version %(version)s". |
**kwargs:t.Any | Extra arguments are passed to option . |
Returns | |
t.Callable[ | Undocumented |
Raises | |
RuntimeError | version could not be detected. |