aiida.cmdline.groups package#
Module with custom implementations of click.Group
.
Submodules#
Subclass of click.Group
that loads subcommands dynamically from entry points.
- class aiida.cmdline.groups.dynamic.DynamicEntryPointCommandGroup(command, entry_point_group: str, entry_point_name_filter: str = '.*', shared_options: Optional[list[click.core.Option]] = None, **kwargs)[source]#
Bases:
aiida.cmdline.groups.verdi.VerdiCommandGroup
Subclass of
click.Group
that loads subcommands dynamically from entry points.A command group using this class will automatically generate the sub commands from the entry points registered in the given
entry_point_group
. The entry points can be additionally filtered using a regex defined for theentry_point_name_filter
keyword. The actual command for each entry point is defined bycommand
, which should take as a first argument the class that corresponds to the entry point. In addition, it should acceptkwargs
which will be the values for the options passed when the command is invoked. The help string of the command will be provided by the docstring of the class registered at the respective entry point. Example usage:def create_instance(cls, **kwargs): instance = cls(**kwargs) instance.store() echo.echo_success(f'Created {cls.__name__}<{instance.pk}>') @click.group('create', cls=DynamicEntryPointCommandGroup, command=create_instance,) def cmd_create(): pass
- __annotations__ = {}#
- __init__(command, entry_point_group: str, entry_point_name_filter: str = '.*', shared_options: Optional[list[click.core.Option]] = None, **kwargs)[source]#
- __module__ = 'aiida.cmdline.groups.dynamic'#
- create_options(entry_point)[source]#
Create the option decorators for the command function for the given entry point.
- Parameters
entry_point – The entry point.
- get_command(ctx, cmd_name)[source]#
Return the command with the given name.
- Parameters
ctx – The
click.Context
.cmd_name – The name of the command.
- Returns
The
click.Command
.
- list_commands(ctx) list[str] [source]#
Return the sorted list of subcommands for this group.
- Parameters
ctx – The
click.Context
.
Subclass of click.Group
for the verdi
CLI.
- class aiida.cmdline.groups.verdi.VerdiCommandGroup(name: Optional[str] = None, commands: Optional[Union[MutableMapping[str, click.core.Command], Sequence[click.core.Command]]] = None, **attrs: Any)[source]#
Bases:
click.core.Group
Subclass of
click.Group
for theverdi
CLI.The class automatically adds the verbosity option to all commands in the interface. It also adds some functionality to provide suggestions of commands in case the user provided command name does not exist.
- __annotations__ = {}#
- __module__ = 'aiida.cmdline.groups.verdi'#
- static add_verbosity_option(cmd: click.core.Command)[source]#
Apply the
verbosity
option to the command, which is common to allverdi
commands.
- context_class#
- fail_with_suggestions(ctx: click.core.Context, cmd_name: str)[source]#
Fail the command while trying to suggest commands to resemble the requested
cmd_name
.
- get_command(ctx: click.core.Context, cmd_name: str) click.core.Command | None [source]#
Return the command that corresponds to the requested
cmd_name
.This method is overridden from the base class in order to two functionalities:
If the command is found, automatically add the verbosity option.
If the command is not found, attempt to provide a list of suggestions with existing commands that resemble the requested command name.
Note that if the command is not found and
resilient_parsing
is set to True on the context, then the latter feature is disabled because most likely we are operating in tab-completion mode.
- group(*args, **kwargs) click.core.Group [source]#
Ensure that sub command groups use the same class but do not override an explicitly set value.