LoaderCLI¶
-
class
lsst.daf.butler.cli.butler.
LoaderCLI
(*args, **kwargs)¶ Bases:
click.core.MultiCommand
,abc.ABC
Extends
click.MultiCommand
, which dispatches to subcommands, to load subcommands at runtime.Attributes Summary
allow_extra_args
allow_interspersed_args
ignore_unknown_options
localCmdPkg
localCmdPkg identifies the location of the commands that are in this package. Methods Summary
__call__
(*args, **kwargs)Alias for main()
.collect_usage_pieces
(ctx)Returns all the pieces that go into the usage line and returns it as a list of strings. format_commands
(ctx, formatter)Extra format methods for multi methods that adds all the commands after the options. format_epilog
(ctx, formatter)Writes the epilog into the formatter if it exists. format_help
(ctx, formatter)Writes the help into the formatter if it exists. format_help_text
(ctx, formatter)Writes the help text to the formatter if it exists. format_options
(ctx, formatter)Writes all the options into the formatter if they exist. format_usage
(ctx, formatter)Writes the usage line into the formatter. getLocalCommands
()Get the commands offered by the local package. getPluginList
()Get the list of importable yaml files that contain cli data for this command. get_command
(ctx, name)Used by Click to get a single command for execution. get_help
(ctx)Formats the help into a string and returns it. get_help_option
(ctx)Returns the help option object. get_help_option_names
(ctx)Returns the names for the help option. get_params
(ctx)get_short_help_str
([limit])Gets short help for the command or makes it by shortening the long help string. get_usage
(ctx)Formats the usage line into a string and returns it. invoke
(ctx)Given a context, this invokes the attached callback (if it exists) in the right way. list_commands
(ctx)Used by Click to get all the commands that can be called by the butler command, it is used to generate the –help output. main
([args, prog_name, complete_var, …])This is the way to invoke a script with all the bells and whistles as a command line application. make_context
(info_name, args[, parent])This function when given an info name and arguments will kick off the parsing and create a new Context
.make_parser
(ctx)Creates the underlying option parser for this command. 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. resolve_command
(ctx, args)resultcallback
([replace])Adds a result callback to the chain command. Attributes Documentation
-
allow_extra_args
= True¶
-
allow_interspersed_args
= False¶
-
ignore_unknown_options
= False¶
-
localCmdPkg
¶ localCmdPkg identifies the location of the commands that are in this package.
getLocalCommands
assumes that the commands can be found inlocalCmdPkg.__all__
, if this is not the case then getLocalCommands should be overridden.Returns: - package :
str
The fully qualified location of this package.
- package :
Methods Documentation
-
collect_usage_pieces
(ctx)¶ Returns all the pieces that go into the usage line and returns it as a list of strings.
-
format_commands
(ctx, formatter)¶ Extra format methods for multi methods that adds all the commands after the options.
-
format_epilog
(ctx, formatter)¶ Writes the epilog into the formatter if it exists.
-
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:
-
format_help_text
(ctx, formatter)¶ Writes the help text to the formatter if it exists.
-
format_options
(ctx, formatter)¶ Writes all the options into the formatter if they exist.
-
format_usage
(ctx, formatter)¶ Writes the usage line into the formatter.
This is a low-level method called by
get_usage()
.
-
getLocalCommands
() → collections.defaultdict[str, list]¶ Get the commands offered by the local package. This assumes that the commands can be found in
localCmdPkg.__all__
, if this is not the case then this function should be overridden.Returns:
-
classmethod
getPluginList
() → list¶ Get the list of importable yaml files that contain cli data for this command.
Returns:
-
get_command
(ctx: click.core.Context, name: str) → click.core.Command | None[click.core.Command, None]¶ Used by Click to get a single command for execution.
Parameters: - ctx :
click.Context
The current Click context.
- name :
str
The name of the command to return.
Returns: - command :
click.Command
A Command that wraps a callable command function.
- ctx :
-
get_help
(ctx)¶ Formats the help into a string and returns it.
Calls
format_help()
internally.
-
get_help_option
(ctx)¶ Returns the help option object.
-
get_help_option_names
(ctx)¶ Returns the names for the help option.
-
get_params
(ctx)¶
-
get_short_help_str
(limit=45)¶ Gets short help for the command or makes it by shortening the long help string.
-
get_usage
(ctx)¶ Formats the usage line into a string and returns it.
Calls
format_usage()
internally.
-
invoke
(ctx)¶ Given a context, this invokes the attached callback (if it exists) in the right way.
-
list_commands
(ctx: click.core.Context) → list¶ Used by Click to get all the commands that can be called by the butler command, it is used to generate the –help output.
Parameters: - ctx :
click.Context
The current Click context.
Returns: - ctx :
-
main
(args=None, prog_name=None, complete_var=None, standalone_mode=True, **extra)¶ 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
.New in version 3.0: Added the
standalone_mode
flag to control the standalone mode.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 ofinvoke()
. - extra – extra keyword arguments are forwarded to the context
constructor. See
Context
for more information.
- args – the arguments that should be used for parsing. If not
provided,
-
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.Parameters: - info_name – the info name for this invokation. 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 script.
- args – the arguments to parse as list of strings.
- parent – the parent context if available.
- extra – extra keyword arguments forwarded to the context constructor.
-
make_parser
(ctx)¶ Creates the underlying option parser for this command.
-
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()
.
-
resolve_command
(ctx, args)¶
-
resultcallback
(replace=False)¶ Adds a result callback to the chain 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.resultcallback() def process_result(result, input): return result + input
New in version 3.0.
Parameters: replace – if set to True
an already existing result callback will be removed.
-