palgen.application.runner
#
Module Contents#
- class palgen.application.runner.CommandLoader(name=None, commands=None, **attrs)#
palgen.application.runner.CommandLoader click.core.BaseCommand click.core.BaseCommand click.core.Command click.core.Command click.core.Command->click.core.BaseCommand click.core.Group click.core.Group click.core.MultiCommand click.core.MultiCommand click.core.Group->click.core.MultiCommand click.core.MultiCommand->click.core.Command palgen.application.runner.CommandLoader palgen.application.runner.CommandLoader palgen.application.runner.CommandLoader palgen.application.runner.CommandLoader->click.core.Group A group allows a command to have subcommands attached. This is the most common way to implement nesting in Click.
- Parameters:
name (Optional[str]) – The name of the group command.
commands (Optional[Union[MutableMapping[str, Command], Sequence[Command]]]) – A dict mapping names to
Command
objects. Can also be a list ofCommand
, which will useCommand.name
to create the dict.attrs (Any) – Other command arguments described in
MultiCommand
,Command
, andBaseCommand
.
Changed in version 8.0: The
commands
argument can be a list of command objects.- allow_extra_args = True#
- allow_interspersed_args = False#
- context_class: Type[Context]#
- ignore_unknown_options = False#
- ensure_palgen(ctx)#
- Parameters:
ctx (click.Context) –
- list_commands(ctx)#
Returns a list of subcommand names in the order they should appear.
- get_command(ctx, cmd_name)#
Given a context and a command name, this returns a
Command
object if it exists or returns None.- Parameters:
ctx (click.Context) –
cmd_name (str) –
- format_commands(ctx, formatter)#
Extra format methods for multi methods that adds all the commands after the options.
- Parameters:
ctx (click.core.Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- format_options(ctx, formatter)#
Writes all the options into the formatter if they exist.
- Parameters:
ctx (click.core.Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- add_command(cmd, name=None)#
Registers another
Command
with this group. If the name is not provided, the name of the command is used.- Parameters:
cmd (Command) –
name (Optional[str]) –
- Return type:
None
- command(__func: Callable[Ellipsis, Any]) Command #
- command(*args: Any, **kwargs: Any) Callable[[Callable[Ellipsis, Any]], Command]
A shortcut decorator for declaring and attaching a command to the group. This takes the same arguments as
command()
and immediately registers the created command with this group by callingadd_command()
.To customize the command class used, set the
command_class
attribute.Changed in version 8.1: This decorator can be applied without parentheses.
Changed in version 8.0: Added the
command_class
attribute.
- group(__func: Callable[Ellipsis, Any]) Group #
- group(*args: Any, **kwargs: Any) Callable[[Callable[Ellipsis, Any]], Group]
A shortcut decorator for declaring and attaching a group to the group. This takes the same arguments as
group()
and immediately registers the created group with this group by callingadd_command()
.To customize the group class used, set the
group_class
attribute.Changed in version 8.1: This decorator can be applied without parentheses.
Changed in version 8.0: Added the
group_class
attribute.
- to_info_dict(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.- Parameters:
ctx (Context) – A
Context
representing this command.- Return type:
Dict[str, Any]
New in version 8.0.
- collect_usage_pieces(ctx)#
Returns all the pieces that go into the usage line and returns it as a list of strings.
- Parameters:
ctx (Context) –
- Return type:
List[str]
- result_callback(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
- Parameters:
replace (bool) – if set to True an already existing result callback will be removed.
- Return type:
Callable[[F], F]
Changed in version 8.0: Renamed from
resultcallback
.New in version 3.0.
- parse_args(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()
.
- invoke(ctx)#
Given a context, this invokes the attached callback (if it exists) in the right way.
- Parameters:
ctx (Context) –
- Return type:
Any
- resolve_command(ctx, args)#
- shell_complete(ctx, incomplete)#
Return a list of completions for the incomplete value. Looks at the names of options, subcommands, and chained multi-commands.
- Parameters:
ctx (Context) – Invocation context for this command.
incomplete (str) – Value being completed. May be empty.
- Return type:
List[click.shell_completion.CompletionItem]
New in version 8.0.
- get_usage(ctx)#
Formats the usage line into a string and returns it.
Calls
format_usage()
internally.- Parameters:
ctx (Context) –
- Return type:
- get_params(ctx)#
- Parameters:
ctx (Context) –
- Return type:
List[Parameter]
- format_usage(ctx, formatter)#
Writes the usage line into the formatter.
This is a low-level method called by
get_usage()
.- Parameters:
ctx (Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- get_help_option_names(ctx)#
Returns the names for the help option.
- Parameters:
ctx (Context) –
- Return type:
List[str]
- get_help_option(ctx)#
Returns the help option object.
- Parameters:
ctx (Context) –
- Return type:
Optional[Option]
- make_parser(ctx)#
Creates the underlying option parser for this command.
- Parameters:
ctx (Context) –
- Return type:
click.parser.OptionParser
- get_help(ctx)#
Formats the help into a string and returns it.
Calls
format_help()
internally.- Parameters:
ctx (Context) –
- Return type:
- get_short_help_str(limit=45)#
Gets short help for the command or makes it by shortening the long help string.
- format_help(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 (Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- format_help_text(ctx, formatter)#
Writes the help text to the formatter if it exists.
- Parameters:
ctx (Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- format_epilog(ctx, formatter)#
Writes the epilog into the formatter if it exists.
- Parameters:
ctx (Context) –
formatter (click.formatting.HelpFormatter) –
- Return type:
None
- make_context(info_name, args, parent=None, **extra)#
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.- Parameters:
info_name (Optional[str]) – 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’s the name of the command.
args (List[str]) – the arguments to parse as list of strings.
parent (Optional[Context]) – the parent context if available.
extra (Any) – extra keyword arguments forwarded to the context constructor.
- Return type:
Context
Changed in version 8.0: Added the
context_class
attribute.
- main(args: Sequence[str] | None = None, prog_name: str | None = None, complete_var: str | None = None, standalone_mode: typing_extensions.Literal[True] = True, **extra: Any) typing_extensions.NoReturn #
- main(args: Sequence[str] | None = None, prog_name: str | None = None, complete_var: str | None = None, standalone_mode: bool = ..., **extra: Any) Any
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 – the arguments that should be used for parsing. If not provided,
sys.argv[1:]
is used.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]
.complete_var – the environment variable that controls the bash completion support. The default is
"_<prog_name>_COMPLETE"
with prog_name in uppercase.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
invoke()
.windows_expand_args – Expand glob patterns, user dir, and env vars in command line args on Windows.
extra – extra keyword arguments are forwarded to the context constructor. See
Context
for more information.
Changed in version 8.0.1: Added the
windows_expand_args
parameter to allow disabling command line arg expansion on Windows.Changed in version 8.0: When taking arguments from
sys.argv
on Windows, glob patterns, user dir, and env vars are expanded.Changed in version 3.0: Added the
standalone_mode
parameter.
- palgen.application.runner.main(ctx, debug, version, config, extra_folders, dependencies, jobs, output)#
- Parameters:
debug (bool) –
version (bool) –
config (pathlib.Path) –
extra_folders (palgen.application.util.ListParam[pathlib.Path]) –
dependencies (palgen.application.util.ListParam[pathlib.Path]) –
jobs (int) –
output (pathlib.Path) –
- palgen.application.runner.check_direct_run()#
This hack allows running extensions directly