mlsimkit.common.cli.BaseGroup

class mlsimkit.common.cli.BaseGroup(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, invoke_without_command: bool = False, no_args_is_help: bool | None = None, subcommand_metavar: str | None = None, chain: bool = False, result_callback: Callable[[...], Any] | None = None, **kwargs: Any)

A Click group that handles instantiating Pydantic models from flattened CLI params.

This class extends the click.Group class and overrides the format_options(), parse_args(), invoke(), and command() methods to handle instantiating Pydantic models from the command-line parameters.

format_options(ctx, formatter)

Format the group options for display.

parse_args(ctx, args)

Parse the command-line arguments and detect if help was requested.

invoke(ctx)

Invoke the group and instantiate Pydantic models from the parameters.

command(args, kwargs)

Decorate a command within the group with custom behavior.

__init__(name: str | None = None, commands: MutableMapping[str, Command] | Sequence[Command] | None = None, invoke_without_command: bool = False, no_args_is_help: bool | None = None, subcommand_metavar: str | None = None, chain: bool = False, result_callback: Callable[[...], Any] | None = None, **kwargs: Any) None

Methods

__init__([name, commands, ...])

add_command(cmd[, name])

Registers another Command with this group.

collect_usage_pieces(ctx)

Returns all the pieces that go into the usage line and returns it as a list of strings.

command(*args, **kwargs)

A shortcut decorator for declaring and attaching a command to the group.

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.

get_command(ctx, cmd_name)

Given a context and a command name, this returns a Command object if it exists or returns None.

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.

group(*args, **kwargs)

A shortcut decorator for declaring and attaching a group to the group.

invoke(ctx)

Given a context, this invokes the attached callback (if it exists) in the right way.

list_commands(ctx)

Returns a list of subcommand names in the order they should appear.

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)

resolve_command(ctx, args)

result_callback([replace])

Adds a result callback to the command.

shell_complete(ctx, incomplete)

Return a list of completions for the incomplete value.

to_info_dict(ctx)

Attributes

allow_extra_args

the default for the Context.allow_extra_args flag.

allow_interspersed_args

the default for the Context.allow_interspersed_args flag.

command_class

If set, this is used by the group's command() decorator as the default Command class.

group_class

If set, this is used by the group's group() decorator as the default Group class.

ignore_unknown_options

the default for the Context.ignore_unknown_options flag.

commands

The registered subcommands by their exported names.

name

the name the command thinks it has.

context_settings

an optional dictionary with defaults passed to the context.

callback

the callback to execute when the command fires.

params

the list of parameters for this command in the order they should show up in the help page and execute.

command(*args: Any, **kwargs: Any) Callable[[Callable[[...], 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 calling add_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.

format_options(ctx, formatter)

Writes all the options into the formatter if they exist.

invoke(ctx)

Given a context, this invokes the attached callback (if it exists) in the right way.

parse_args(ctx: Context, args: list[str]) list[str]