class documentation

class BaseCommand: (source)

Known subclasses: click.core.Command

View In Hierarchy

The base command implements the minimal API contract of commands. Most code will never use this as it does not implement a lot of useful functionality but it can act as the direct subclass of alternative parsing methods that do not depend on the Click parser. For instance, this can be used to bridge Click and other systems like argparse or docopt. Because base commands do not implement a lot of the API that other parts of Click take for granted, they are not supported for all operations. For instance, they cannot be used with the decorators usually and they have no built-in callback system. .. versionchanged:: 2.0 Added the `context_settings` parameter. :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.

Method __call__ Alias for :meth:`main`.
Method __init__ Undocumented
Method __repr__ Undocumented
Method get_help Undocumented
Method get_usage Undocumented
Method invoke Given a context, this invokes the command. The default implementation is raising a not implemented error.
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_context 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.
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 :meth:`make_context`.
Method shell_complete Return a list of completions for the incomplete value. Looks at the names of 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
Class Variable ignore_unknown_options Undocumented
Instance Variable context_settings Undocumented
Instance Variable name Undocumented
Method _main_shell_completion Check if the shell is asking for tab completion, process that, then exit early. Called from :meth:`main` before the program is invoked.
def __call__(self, *args, **kwargs): (source)

Alias for :meth:`main`.

Parameters
*args:t.AnyUndocumented
**kwargs:t.AnyUndocumented
Returns
t.AnyUndocumented
def __init__(self, name, context_settings=None): (source)
overridden in click.core.Command

Undocumented

Parameters
name:t.Optional[str]Undocumented
context_settings:t.Optional[t.Dict[str, t.Any]]Undocumented
def __repr__(self): (source)

Undocumented

Returns
strUndocumented
def get_help(self, ctx): (source)
overridden in click.core.Command

Undocumented

Parameters
ctx:ContextUndocumented
Returns
strUndocumented
def get_usage(self, ctx): (source)
overridden in click.core.Command

Undocumented

Parameters
ctx:ContextUndocumented
Returns
strUndocumented
def invoke(self, ctx): (source)
overridden in click.core.Command

Given a context, this invokes the command. The default implementation is raising a not implemented error.

Parameters
ctx:ContextUndocumented
Returns
t.AnyUndocumented
def main(self, args=None, prog_name=None, complete_var=None, standalone_mode=True, windows_expand_args=True, **extra): (source)

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. This method is also available by directly calling the instance of a :class:`Command`. :param args: the arguments that should be used for parsing. If not provided, ``sys.argv[1:]`` is used. :param prog_name: the program name that should be used. By default the program name is constructed by taking the file name from ``sys.argv[0]``. :param complete_var: the environment variable that controls the bash completion support. The default is ``"_<prog_name>_COMPLETE"`` with prog_name in uppercase. :param standalone_mode: the default behavior is to invoke the script in standalone mode. Click will then handle exceptions and convert them into error messages and the function will never return but shut down the interpreter. If this is set to `False` they will be propagated to the caller and the return value of this function is the return value of :meth:`invoke`. :param windows_expand_args: Expand glob patterns, user dir, and env vars in command line args on Windows. :param extra: extra keyword arguments are forwarded to the context constructor. See :class:`Context` for more information. .. versionchanged:: 8.0.1 Added the ``windows_expand_args`` parameter to allow disabling command line arg expansion on Windows. .. versionchanged:: 8.0 When taking arguments from ``sys.argv`` on Windows, glob patterns, user dir, and env vars are expanded. .. versionchanged:: 3.0 Added the ``standalone_mode`` parameter.

Parameters
args:t.Optional[t.Sequence[str]]Undocumented
prog_name:t.Optional[str]Undocumented
complete_var:t.Optional[str]Undocumented
standalone_mode:boolUndocumented
windows_expand_args:boolUndocumented
**extra:t.AnyUndocumented
Returns
t.AnyUndocumented
def make_context(self, info_name, args, parent=None, **extra): (source)

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. To quickly customize the context class used without overriding this method, set the :attr:`context_class` attribute. :param info_name: the info name for this invocation. Generally this is the most descriptive name for the script or command. For the toplevel script it's usually the name of the script, for commands below it it's the name of the command. :param args: the arguments to parse as list of strings. :param parent: the parent context if available. :param extra: extra keyword arguments forwarded to the context constructor. .. versionchanged:: 8.0 Added the :attr:`context_class` attribute.

Parameters
info_name:t.Optional[str]Undocumented
args:t.List[str]Undocumented
parent:t.Optional[Context]Undocumented
**extra:t.AnyUndocumented
Returns
ContextUndocumented
def parse_args(self, ctx, args): (source)
overridden in click.core.Command

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`.

Parameters
ctx:ContextUndocumented
args:t.List[str]Undocumented
Returns
t.List[str]Undocumented
def shell_complete(self, ctx, incomplete): (source)
overridden in click.core.Command

Return a list of completions for the incomplete value. Looks at the names of chained multi-commands. Any command could be part of a chained multi-command, so sibling commands are valid at any point during command completion. Other command classes will return more completions. :param ctx: Invocation context for this command. :param incomplete: Value being completed. May be empty. .. versionadded:: 8.0

Parameters
ctx:ContextUndocumented
incomplete:strUndocumented
Returns
t.List[CompletionItem]Undocumented
def to_info_dict(self, ctx): (source)
overridden in click.core.Command

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:ContextUndocumented
Returns
t.Dict[str, t.Any]Undocumented
allow_extra_args: bool = (source)

Undocumented

allow_interspersed_args: bool = (source)

Undocumented

ignore_unknown_options: bool = (source)

Undocumented

context_settings: t.Dict[str, t.Any] = (source)

Undocumented

name = (source)

Undocumented

def _main_shell_completion(self, ctx_args, prog_name, complete_var=None): (source)

Check if the shell is asking for tab completion, process that, then exit early. Called from :meth:`main` before the program is invoked. :param prog_name: Name of the executable in the shell. :param complete_var: Name of the environment variable that holds the completion instruction. Defaults to ``_{PROG_NAME}_COMPLETE``.

Parameters
ctx_args:t.Dict[str, t.Any]Undocumented
prog_name:strUndocumented
complete_var:t.Optional[str]Undocumented