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 |
Undocumented |
Method | get |
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 |
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 |
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 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. |
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.Command
Undocumented
Parameters | |
name:t.Optional[ | Undocumented |
contextt.Optional[ | Undocumented |
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[ | Undocumented |
progt.Optional[ | Undocumented |
completet.Optional[ | Undocumented |
standalonebool | Undocumented |
windowsbool | Undocumented |
**extra:t.Any | Undocumented |
Returns | |
t.Any | Undocumented |
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 | |
infot.Optional[ | Undocumented |
args:t.List[ | Undocumented |
parent:t.Optional[ | Undocumented |
**extra:t.Any | Undocumented |
Returns | |
Context | Undocumented |
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:Context | Undocumented |
incomplete:str | Undocumented |
Returns | |
t.List[ | Undocumented |
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:Context | Undocumented |
Returns | |
t.Dict[ | Undocumented |
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 | |
ctxt.Dict[ | Undocumented |
progstr | Undocumented |
completet.Optional[ | Undocumented |