gufo.thor.cli.base¶
CLI entrypoint and shared Click context.
CLIDispatcher
¶
Bases: Group
Click command group that dynamically discovers CLI entrypoints.
get_command(ctx, cmd_name)
¶
Get a CLI command by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Current CLI context. |
required |
cmd_name
|
str
|
Command name. |
required |
Returns:
| Type | Description |
|---|---|
Command | None
|
The command, or |
invoke(ctx)
¶
Run the selected command and convert Thor cancellation to exit 1.
list_commands(ctx)
¶
List available CLI commands.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Current CLI context. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of available command names. |
Context
¶
CLI execution context.
verbose
property
writable
¶
Whether verbose output is enabled.
debug(msg)
¶
Print a debug message to standard output if verbose mode is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to print. |
required |
die(msg=None)
¶
Print an error message and terminate the process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str | None
|
Optional error message to print. |
None
|
print(msg)
¶
Print a message to standard output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
str
|
Message to print. |
required |
Entrypoint
¶
CLI entrypoint registered with the Gufo Loader.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Command
|
Click command associated with the entrypoint. |
required |
get_command()
¶
Return the Click command associated with the entrypoint.
Returns:
| Type | Description |
|---|---|
Command
|
Click command registered as the entrypoint. |
entrypoint(fn)
¶
Register a Click command as a Gufo Thor CLI entrypoint.
The decorator must be placed above all Click decorators::
@entrypoint
@click.command()
def foo() -> None:
...
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Command
|
Click command to register. |
required |
Returns:
| Type | Description |
|---|---|
Entrypoint
|
Entrypoint instance. |
main(ctx, verbose)
¶
Gufo Thor command-line interface.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Context
|
Current CLI context. |
required |
verbose
|
bool
|
Enable verbose output. |
required |
prepared(fn)
¶
Mark a CLI callback as requiring configuration preparation.
The decorator must be placed below all Click decorators::
@entrypoint
@click.command()
@prepared
def foo() -> None:
...
This ensures that prepared is applied to the callback before
Click creates the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., object]
|
CLI callback to mark for configuration preparation. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., object]
|
The unchanged CLI callback. |