Bases: Group
A click Group that can lazily load subcommands
This class extends the click.Group class to allow for subcommands to be
lazily loaded from a module path.
It is useful when you have a large number of subcommands that you don't
want to load until they are actually needed.
Available with the cli
extra dependencies.
Source code in fluid/utils/lazy.py
| def __init__(
self,
*,
lazy_subcommands: dict[str, str] | None = None,
**kwargs: Any,
):
super().__init__(**kwargs)
self.lazy_subcommands = lazy_subcommands or {}
|
lazy_subcommands
instance-attribute
lazy_subcommands = lazy_subcommands or {}
list_commands
Source code in fluid/utils/lazy.py
| def list_commands(self, ctx: click.Context) -> list[str]:
commands = super().list_commands(ctx)
commands.extend(self.lazy_subcommands)
return sorted(commands)
|
get_command
get_command(ctx, cmd_name)
Source code in fluid/utils/lazy.py
| def get_command(self, ctx: click.Context, cmd_name: str) -> click.Command | None:
if cmd_name in self.lazy_subcommands:
return self._lazy_load(cmd_name)
return super().get_command(ctx, cmd_name)
|