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.
context_settings
parameter.Parameters | |
name | the name of the command to use unless a group overrides it. |
context_settings | an optional dictionary with defaults that are passed to the context object. |
Method | __call__ |
Alias for main . |
Method | __init__ |
Undocumented |
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 | 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 |
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. |
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 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 |
main
.Parameters | |
*args:t.Any | Undocumented |
**kwargs:t.Any | Undocumented |
Returns | |
t.Any | Undocumented |
click.core.Command
Undocumented
Parameters | |
name:t.Optional[ | Undocumented |
context_settings:t.Optional[ | Undocumented |
main
before the
program is invoked.Parameters | |
ctx_args:t.Dict[ | Undocumented |
prog_name:str | Name of the executable in the shell. |
complete_var:t.Optional[ | Name of the environment variable that holds the completion instruction. Defaults to _{PROG_NAME}_COMPLETE. |
click.core.Command
Undocumented
Parameters | |
ctx:Context | Undocumented |
Returns | |
str | Undocumented |
click.core.Command
Undocumented
Parameters | |
ctx:Context | Undocumented |
Returns | |
str | Undocumented |
click.core.Command
Parameters | |
ctx:Context | Undocumented |
Returns | |
t.Any | 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 Command
.
Parameters | |
args:t.Optional[ | the arguments that should be used for parsing. If not provided, sys.argv[1:] is used. |
prog_name:t.Optional[ | the program name that should be used. By default the program name is constructed by taking the file name from sys.argv[0]. |
complete_var:t.Optional[ | the environment variable that controls the bash completion support. The default is "_<prog_name>_COMPLETE" with prog_name in uppercase. |
standalone_mode:bool | 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 invoke . |
windows_expand_args:bool | Expand glob patterns, user dir, and env vars in command line args on Windows. |
**extra:t.Any | extra keyword arguments are forwarded to the context
constructor. See Context for more information. |
Returns | |
t.Any | Undocumented |
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.
To quickly customize the context class used without overriding
this method, set the context_class
attribute.
context_class
attribute.Parameters | |
info_name:t.Optional[ | 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. |
args:t.List[ | the arguments to parse as list of strings. |
parent:t.Optional[ | the parent context if available. |
**extra:t.Any | extra keyword arguments forwarded to the context constructor. |
Returns | |
Context | Undocumented |
click.core.Command
make_context
.Parameters | |
ctx:Context | Undocumented |
args:t.List[ | Undocumented |
Returns | |
t.List[ | 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.
Parameters | |
ctx:Context | Invocation context for this command. |
incomplete:str | Value being completed. May be empty. |
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 click.Context.to_info_dict
to traverse the entire
CLI structure.
Parameters | |
ctx:Context | A Context representing this command. |
Returns | |
t.Dict[ | Undocumented |