class documentation

class MultiCommand(Command):

Known subclasses: click.core.CommandCollection, click.core.Group

View In Hierarchy

A multi command is the basic implementation of a command that dispatches to subcommands. The most common version is the Group.
Parameters
invoke​_without​_commandthis controls how the multi command itself is invoked. By default it's only invoked if a subcommand is provided.
no​_args​_is​_helpthis controls what happens if no arguments are provided. This option is enabled by default if invoke_without_command is disabled or disabled if it's enabled. If enabled this will add --help as argument if no arguments are passed.
subcommand​_metavarthe string that is used in the documentation to indicate the subcommand place.
chainif this is set to True chaining of multiple subcommands is enabled. This restricts the form of commands in that they cannot have optional arguments but it allows multiple commands to be chained together.
result​_callbackThe result callback to attach to this multi command. This can be set or changed later with the result_callback decorator.
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​_commands Extra format methods for multi methods that adds all the commands after the options.
Method format​_options Writes all the options into the formatter if they exist.
Method get​_command Given a context and a command name, this returns a Command object if it exists or returns None.
Method invoke Given a context, this invokes the attached callback (if it exists) in the right way.
Method list​_commands Returns a list of subcommand names in the order they should appear.
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 resolve​_command Undocumented
Method result​_callback No summary
Method resultcallback Undocumented
Method shell​_complete Return a list of completions for the incomplete value. Looks at the names of options, subcommands, 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.
Class Variable allow​_extra​_args Undocumented
Class Variable allow​_interspersed​_args Undocumented
Instance Variable ​_result​_callback Undocumented
Instance Variable chain Undocumented
Instance Variable invoke​_without​_command Undocumented
Instance Variable no​_args​_is​_help Undocumented
Instance Variable subcommand​_metavar Undocumented

Inherited from Command:

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​_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 make​_parser Creates the underlying option parser for 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 options​_metavar Undocumented
Instance Variable params Undocumented
Instance Variable short​_help Undocumented

Inherited from BaseCommand (via Command):

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 ignore​_unknown​_options Undocumented
Instance Variable context​_settings Undocumented
Instance Variable name Undocumented
def __init__(self, name=None, invoke_without_command=False, no_args_is_help=None, subcommand_metavar=None, chain=False, result_callback=None, **attrs):

Undocumented

Parameters
name:t.Optional[str]Undocumented
invoke​_without​_command:boolUndocumented
no​_args​_is​_help:t.Optional[bool]Undocumented
subcommand​_metavar:t.Optional[str]Undocumented
chain:boolUndocumented
result​_callback:t.Optional[t.Callable[..., t.Any]]Undocumented
**attrs:t.AnyUndocumented
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_commands(self, ctx, formatter):
Extra format methods for multi methods that adds all the commands after the options.
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 get_command(self, ctx, cmd_name):
Given a context and a command name, this returns a Command object if it exists or returns None.
Parameters
ctx:ContextUndocumented
cmd​_name:strUndocumented
Returns
t.Optional[Command]Undocumented
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 list_commands(self, ctx):
Returns a list of subcommand names in the order they should appear.
Parameters
ctx:ContextUndocumented
Returns
t.List[str]Undocumented
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 resolve_command(self, ctx, args):

Undocumented

Parameters
ctx:ContextUndocumented
args:t.List[str]Undocumented
Returns
t.Tuple[t.Optional[str], t.Optional[Command], t.List[str]]Undocumented
def result_callback(self, replace=False):

Adds a result callback to the command. By default if a result callback is already registered this will chain them but this can be disabled with the replace parameter. The result callback is invoked with the return value of the subcommand (or the list of return values from all subcommands if chaining is enabled) as well as the parameters as they would be passed to the main callback.

Example:

@click.group()
@click.option('-i', '--input', default=23)
def cli(input):
    return 42

@cli.result_callback()
def process_result(result, input):
    return result + input
Changed in version 8.0: Renamed from resultcallback.
New in version 3.0.
Parameters
replace:boolif set to True an already existing result callback will be removed.
Returns
t.Callable[[F], F]Undocumented
def resultcallback(self, replace=False):

Undocumented

Parameters
replace:boolUndocumented
Returns
t.Callable[[F], F]Undocumented
def shell_complete(self, ctx, incomplete):

Return a list of completions for the incomplete value. Looks at the names of options, subcommands, 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
allow_extra_args: bool =
allow_interspersed_args: bool =
_result_callback =

Undocumented

chain =

Undocumented

invoke_without_command =

Undocumented

no_args_is_help =

Undocumented

subcommand_metavar =

Undocumented