class documentation

class Command(BaseCommand):

Known subclasses: click.core.MultiCommand

View In Hierarchy

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.

Changed in version 2.0: Added the context_settings parameter.
Changed in version 8.0: Added repr showing the command name
Changed in version 7.1: Added the no_args_is_help parameter.
Parameters
namethe name of the command to use unless a group overrides it.
context​_settingsan optional dictionary with defaults that are passed to the context object.
callbackthe callback to invoke. This is optional.
paramsthe parameters to register with this command. This can be either Option or Argument objects.
helpthe help string to use for this command.
epiloglike the help string but it's printed at the end of the help page after everything else.
short​_helpthe short help to use for this command. This is shown on the command listing of the parent command.
add​_help​_optionby default each command registers a --help option. This can be disabled by this parameter.
no​_args​_is​_helpthis 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
hiddenhide this command from help outputs.
deprecatedissues a message indicating that the command is deprecated.
Method __init__ Undocumented
Method collect​_usage​_pieces Returns all the pieces that go into the usage line and returns it as a list of strings.
Method format​_epilog Writes the epilog into the formatter if it exists.
Method format​_help Writes the help into the formatter if it exists.
Method format​_help​_text Writes the help text to the formatter if it exists.
Method format​_options Writes all the options into the formatter if they exist.
Method format​_usage Writes the usage line into the formatter.
Method get​_help Formats the help into a string and returns it.
Method get​_help​_option Returns the help option object.
Method get​_help​_option​_names Returns the names for the help option.
Method get​_params Undocumented
Method get​_short​_help​_str Gets short help for the command or makes it by shortening the long help string.
Method get​_usage 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​_parser Creates the underlying option parser for this command.
Method parse​_args 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 make_context.
Method shell​_complete Return a list of completions for the incomplete value. Looks at the names of options and chained multi-commands.
Method to​_info​_dict Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command.
Instance Variable add​_help​_option Undocumented
Instance Variable callback Undocumented
Instance Variable deprecated Undocumented
Instance Variable epilog Undocumented
Instance Variable help Undocumented
Instance Variable hidden Undocumented
Instance Variable no​_args​_is​_help Undocumented
Instance Variable options​_metavar Undocumented
Instance Variable params Undocumented
Instance Variable short​_help Undocumented

Inherited from BaseCommand:

Method __call__ Alias for main.
Method __repr__ Undocumented
Method ​_main​_shell​_completion Check if the shell is asking for tab completion, process that, then exit early. Called from main before the program is invoked.
Method main No summary
Method make​_context This function when given an info name and arguments will kick off the parsing and create a new Context. It does not invoke the actual command callback though.
Class Variable allow​_extra​_args Undocumented
Class Variable allow​_interspersed​_args Undocumented
Class Variable ignore​_unknown​_options Undocumented
Instance Variable context​_settings Undocumented
Instance Variable name Undocumented
def __init__(self, name, context_settings=None, callback=None, params=None, help=None, epilog=None, short_help=None, options_metavar='[OPTIONS]', add_help_option=True, no_args_is_help=False, hidden=False, deprecated=False):

Undocumented

Parameters
name:t.Optional[str]Undocumented
context​_settings:t.Optional[t.Dict[str, t.Any]]Undocumented
callback:t.Optional[t.Callable[..., t.Any]]Undocumented
params:t.Optional[t.List[Parameter]]Undocumented
help:t.Optional[str]Undocumented
epilog:t.Optional[str]Undocumented
short​_help:t.Optional[str]Undocumented
options​_metavar:t.Optional[str]Undocumented
add​_help​_option:boolUndocumented
no​_args​_is​_help:boolUndocumented
hidden:boolUndocumented
deprecated:boolUndocumented
def collect_usage_pieces(self, ctx):
Returns all the pieces that go into the usage line and returns it as a list of strings.
Parameters
ctx:ContextUndocumented
Returns
t.List[str]Undocumented
def format_epilog(self, ctx, formatter):
Writes the epilog into the formatter if it exists.
Parameters
ctx:ContextUndocumented
formatter:HelpFormatterUndocumented
def format_help(self, ctx, formatter):

Writes the help into the formatter if it exists.

This is a low-level method called by get_help.

This calls the following methods:

Parameters
ctx:ContextUndocumented
formatter:HelpFormatterUndocumented
def format_help_text(self, ctx, formatter):
Writes the help text to the formatter if it exists.
Parameters
ctx:ContextUndocumented
formatter:HelpFormatterUndocumented
def format_options(self, ctx, formatter):
Writes all the options into the formatter if they exist.
Parameters
ctx:ContextUndocumented
formatter:HelpFormatterUndocumented
def format_usage(self, ctx, formatter):

Writes the usage line into the formatter.

This is a low-level method called by get_usage.

Parameters
ctx:ContextUndocumented
formatter:HelpFormatterUndocumented
def get_help(self, ctx):

Formats the help into a string and returns it.

Calls format_help internally.

Parameters
ctx:ContextUndocumented
Returns
strUndocumented
def get_help_option(self, ctx):
Returns the help option object.
Parameters
ctx:ContextUndocumented
Returns
t.Optional[Option]Undocumented
def get_help_option_names(self, ctx):
Returns the names for the help option.
Parameters
ctx:ContextUndocumented
Returns
t.List[str]Undocumented
def get_params(self, ctx):

Undocumented

Parameters
ctx:ContextUndocumented
Returns
t.List[Parameter]Undocumented
def get_short_help_str(self, limit=45):
Gets short help for the command or makes it by shortening the long help string.
Parameters
limit:intUndocumented
Returns
strUndocumented
def get_usage(self, ctx):

Formats the usage line into a string and returns it.

Calls format_usage internally.

Parameters
ctx:ContextUndocumented
Returns
strUndocumented
def invoke(self, ctx):
Given a context, this invokes the attached callback (if it exists) in the right way.
Parameters
ctx:ContextUndocumented
Returns
t.AnyUndocumented
def make_parser(self, ctx):
Creates the underlying option parser for this command.
Parameters
ctx:ContextUndocumented
Returns
OptionParserUndocumented
def parse_args(self, ctx, args):
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 make_context.
Parameters
ctx:ContextUndocumented
args:t.List[str]Undocumented
Returns
t.List[str]Undocumented
def shell_complete(self, ctx, incomplete):

Return a list of completions for the incomplete value. Looks at the names of options and chained multi-commands.

New in version 8.0.
Parameters
ctx:ContextInvocation context for this command.
incomplete:strValue being completed. May be empty.
Returns
t.List[CompletionItem]Undocumented
def to_info_dict(self, ctx):

Gather information that could be useful for a tool generating user-facing documentation. This traverses the entire structure below this command.

Use click.Context.to_info_dict to traverse the entire CLI structure.

New in version 8.0.
Parameters
ctx:ContextA Context representing this command.
Returns
t.Dict[str, t.Any]Undocumented
add_help_option =

Undocumented

callback =

Undocumented

deprecated =

Undocumented

epilog =

Undocumented

help =

Undocumented

hidden =

Undocumented

no_args_is_help =

Undocumented

options_metavar =

Undocumented

params: t.List[Parameter] =

Undocumented

short_help =

Undocumented