Commands are the basic building block of command line interfaces in Click. A basic command handles command line parsing and might dispatch more parsing to commands nested below it. :param name: the name of the command to use unless a group overrides it. :param context_settings: an optional dictionary with defaults that are passed to the context object. :param callback: the callback to invoke. This is optional. :param params: the parameters to register with this command. This can be either :class:`Option` or :class:`Argument` objects. :param help: the help string to use for this command. :param epilog: like the help string but it's printed at the end of the help page after everything else. :param short_help: the short help to use for this command. This is shown on the command listing of the parent command. :param add_help_option: by default each command registers a ``--help`` option. This can be disabled by this parameter. :param no_args_is_help: this controls what happens if no arguments are provided. This option is disabled by default. If enabled this will add ``--help`` as argument if no arguments are passed :param hidden: hide this command from help outputs. :param deprecated: issues a message indicating that the command is deprecated. .. versionchanged:: 8.1 ``help``, ``epilog``, and ``short_help`` are stored unprocessed, all formatting is done when outputting help text, not at init, and is done even if not using the ``@command`` decorator. .. versionchanged:: 8.0 Added a ``repr`` showing the command name. .. versionchanged:: 7.1 Added the ``no_args_is_help`` parameter. .. versionchanged:: 2.0 Added the ``context_settings`` parameter.
Method | __init__ |
Undocumented |
Method | collect |
Returns all the pieces that go into the usage line and returns it as a list of strings. |
Method | format |
Writes the epilog into the formatter if it exists. |
Method | format |
Writes the help into the formatter if it exists. |
Method | format |
Writes the help text to the formatter if it exists. |
Method | format |
Writes all the options into the formatter if they exist. |
Method | format |
Writes the usage line into the formatter. |
Method | get |
Formats the help into a string and returns it. |
Method | get |
Returns the help option object. |
Method | get |
Returns the names for the help option. |
Method | get |
Undocumented |
Method | get |
Gets short help for the command or makes it by shortening the long help string. |
Method | get |
Formats the usage line into a string and returns it. |
Method | invoke |
Given a context, this invokes the attached callback (if it exists) in the right way. |
Method | make |
Creates the underlying option parser for this command. |
Method | parse |
Given a context and a list of arguments this creates the parser and parses the arguments, then modifies the context as necessary. This is automatically invoked by :meth:`make_context`. |
Method | shell |
Return a list of completions for the incomplete value. Looks at the names of options and chained multi-commands. |
Method | to |
Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command. |
Instance Variable | add |
Undocumented |
Instance Variable | callback |
Undocumented |
Instance Variable | deprecated |
Undocumented |
Instance Variable | epilog |
Undocumented |
Instance Variable | help |
Undocumented |
Instance Variable | hidden |
Undocumented |
Instance Variable | no |
Undocumented |
Instance Variable | options |
Undocumented |
Instance Variable | params |
Undocumented |
Instance Variable | short |
Undocumented |
Inherited from BaseCommand
:
Method | __call__ |
Alias for :meth:`main`. |
Method | __repr__ |
Undocumented |
Method | main |
This is the way to invoke a script with all the bells and whistles as a command line application. This will always terminate the application after a call. If this is not wanted, ``SystemExit`` needs to be caught. |
Method | make |
This function when given an info name and arguments will kick off the parsing and create a new :class:`Context`. It does not invoke the actual command callback though. |
Class Variable | allow |
Undocumented |
Class Variable | allow |
Undocumented |
Class Variable | ignore |
Undocumented |
Instance Variable | context |
Undocumented |
Instance Variable | name |
Undocumented |
Method | _main |
Check if the shell is asking for tab completion, process that, then exit early. Called from :meth:`main` before the program is invoked. |
click.core.BaseCommand.__init__
click.core.MultiCommand
Undocumented
Parameters | |
name:t.Optional[ | Undocumented |
contextt.Optional[ | Undocumented |
callback:t.Optional[ | Undocumented |
params:t.Optional[ | Undocumented |
help:t.Optional[ | Undocumented |
epilog:t.Optional[ | Undocumented |
shortt.Optional[ | Undocumented |
optionst.Optional[ | Undocumented |
addbool | Undocumented |
nobool | Undocumented |
hidden:bool | Undocumented |
deprecated:bool | Undocumented |
Writes the epilog into the formatter if it exists.
Parameters | |
ctx:Context | Undocumented |
formatter:HelpFormatter | Undocumented |
Writes the help into the formatter if it exists. This is a low-level method called by :meth:`get_help`. This calls the following methods: - :meth:`format_usage` - :meth:`format_help_text` - :meth:`format_options` - :meth:`format_epilog`
Parameters | |
ctx:Context | Undocumented |
formatter:HelpFormatter | Undocumented |
Writes the help text to the formatter if it exists.
Parameters | |
ctx:Context | Undocumented |
formatter:HelpFormatter | Undocumented |
click.core.MultiCommand
Writes all the options into the formatter if they exist.
Parameters | |
ctx:Context | Undocumented |
formatter:HelpFormatter | Undocumented |
Writes the usage line into the formatter. This is a low-level method called by :meth:`get_usage`.
Parameters | |
ctx:Context | Undocumented |
formatter:HelpFormatter | Undocumented |
Returns the help option object.
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Optional[ | Undocumented |
Creates the underlying option parser for this command.
Parameters | |
ctx:Context | Undocumented |
Returns | |
OptionParser | Undocumented |
click.core.BaseCommand.shell_complete
click.core.MultiCommand
Return a list of completions for the incomplete value. Looks at the names of options and chained multi-commands. :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.BaseCommand.to_info_dict
click.core.MultiCommand
Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command. Use :meth:`click.Context.to_info_dict` to traverse the entire CLI structure. :param ctx: A :class:`Context` representing this command. .. versionadded:: 8.0
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Dict[ | Undocumented |