TyperCLIGroup
This class extends the standard Typer command group to provide dynamic command management during the CLI lifecycle. It ensures that specific execution states are updated and necessary run commands are injected before listing, retrieving, or invoking commands. By overriding core dispatch methods, it integrates custom setup logic seamlessly into the command-line interface.
Methods
list_commands()
@classmethod
def list_commands(
ctx: click.Context
) - > list[str]
Retrieves a list of available command names after ensuring the 'run' command is dynamically added to the CLI group if applicable.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | click.Context | The Click context object containing state and configuration for the current command execution. |
Returns
| Type | Description |
|---|---|
list[str] | A list of strings representing the names of all registered subcommands. |
get_command()
@classmethod
def get_command(
ctx: click.Context,
name: str
) - > Command | None
Fetches a specific command by name, triggering a check to inject the 'run' command into the group before lookup.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | click.Context | The Click context object used to manage state during the command resolution process. |
| name | str | The name of the subcommand to retrieve from the group. |
Returns
| Type | Description |
|---|---|
| `Command | None` |
invoke()
@classmethod
def invoke(
ctx: click.Context
) - > Any
Executes the group's command logic, ensuring the CLI state and 'run' command availability are updated prior to invocation.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | click.Context | The Click context object representing the current execution environment. |
Returns
| Type | Description |
|---|---|
Any | The result of the command execution, which varies based on the invoked subcommand. |
maybe_add_run()
@classmethod
def maybe_add_run(
ctx: click.Context
) - > null
Updates the internal CLI state and conditionally attaches a 'run' command to this group based on the current context.
Parameters
| Name | Type | Description |
|---|---|---|
| ctx | click.Context | The Click context object used to determine if the state needs updating or if the 'run' command should be added. |
Returns
| Type | Description |
|---|---|
null | null |