spakky-typer¶
Typer CLI 통합 — CLI 컨트롤러 자동 등록
Main¶
spakky.plugins.typer.main
¶
Plugin initialization for Typer CLI integration.
Registers post-processor for automatic CLI command registration from @CliController decorated classes.
initialize(app)
¶
Initialize the Typer CLI plugin.
Registers the post-processor for automatic CLI command registration. This function is called automatically by the Spakky framework during plugin loading.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
SpakkyApplication
|
The Spakky application instance. |
required |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/main.py
options: show_root_heading: false
Stereotypes¶
spakky.plugins.typer.stereotypes.cli_controller
¶
CLI controller stereotype for Typer command grouping.
Provides the @CliController stereotype for marking classes as CLI controllers with automatic command registration and the @command decorator for methods.
TyperCommand(name=None, cls=None, context_settings=None, help=None, epilog=None, short_help=None, options_metavar='[OPTIONS]', add_help_option=True, no_args_is_help=False, hidden=False, deprecated=False, rich_help_panel=Default(None))
dataclass
¶
Bases: FunctionAnnotation
Function annotation for marking methods as Typer CLI commands.
Stores all Typer command configuration including name, help text, and command options.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str | None
|
Command name (defaults to method name in kebab-case). |
cls |
type[TyperCommand] | None
|
Custom Typer command class. |
context_settings |
dict[Any, Any] | None
|
Click context settings. |
help |
str | None
|
Command help text. |
epilog |
str | None
|
Text displayed after command help. |
short_help |
str | None
|
Short help text for command list. |
options_metavar |
str
|
Metavar for options display. |
add_help_option |
bool
|
Whether to add --help option. |
no_args_is_help |
bool
|
Show help when no args provided. |
hidden |
bool
|
Hide command from help output. |
deprecated |
bool
|
Mark command as deprecated. |
rich_help_panel |
str | None
|
Rich console help panel name. |
CliController(group_name=None, *, name='', scope=Scope.SINGLETON)
dataclass
¶
Bases: Pod
Stereotype for Typer CLI controllers.
Marks a class as a CLI controller with automatic command registration. Methods decorated with @command will be registered as CLI commands under the specified group name.
Attributes:
| Name | Type | Description |
|---|---|---|
group_name |
str | None
|
CLI command group name (defaults to class name in kebab-case). |
group_name = None
class-attribute
instance-attribute
¶
CLI command group name for organizing related commands.
__call__(obj)
¶
Apply the CLI controller stereotype to a class.
Automatically generates the group name from the class name if not provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
AnyT
|
The class to decorate. |
required |
Returns:
| Type | Description |
|---|---|
AnyT
|
The decorated class registered as a Pod. |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/stereotypes/cli_controller.py
command(name=None, cls=None, context_settings=None, help=None, epilog=None, short_help=None, options_metavar='[OPTIONS]', add_help_option=True, no_args_is_help=False, hidden=False, deprecated=False, rich_help_panel=Default(None))
¶
Decorator to mark a controller method as a CLI command.
Attaches Typer command configuration to the method which will be registered by the TyperCLIPostProcessor during container initialization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Command name (defaults to method name in kebab-case). |
None
|
cls
|
type[TyperCommand] | None
|
Custom Typer command class. |
None
|
context_settings
|
dict[Any, Any] | None
|
Click context settings. |
None
|
help
|
str | None
|
Command help text. |
None
|
epilog
|
str | None
|
Text displayed after command help. |
None
|
short_help
|
str | None
|
Short help text for command list. |
None
|
options_metavar
|
str
|
Metavar for options display. |
'[OPTIONS]'
|
add_help_option
|
bool
|
Whether to add --help option. |
True
|
no_args_is_help
|
bool
|
Show help when no args provided. |
False
|
hidden
|
bool
|
Hide command from help output. |
False
|
deprecated
|
bool
|
Mark command as deprecated. |
False
|
rich_help_panel
|
str | None
|
Rich console help panel name. |
Default(None)
|
Returns:
| Type | Description |
|---|---|
Callable[[Callable[..., AnyT]], Callable[..., AnyT]]
|
A decorator function that attaches the command configuration. |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/stereotypes/cli_controller.py
options: show_root_heading: false
Post Processor¶
spakky.plugins.typer.post_processor
¶
Post-processor for registering Typer CLI commands.
Automatically discovers and registers CLI commands from @CliController decorated classes, with support for both sync and async command handlers.
TyperCLIPostProcessor(app)
¶
Bases: IPostProcessor, IContainerAware, IApplicationContextAware
Post-processor that registers CLI commands from CLI controllers.
Scans @CliController decorated classes for @command decorated methods and automatically registers them as Typer commands with proper dependency injection and async support.
Initialize the Typer CLI post-processor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app
|
Typer
|
The Typer application instance. |
required |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/post_processor.py
set_container(container)
¶
Set the container for dependency injection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
container
|
IContainer
|
The IoC container. |
required |
set_application_context(application_context)
¶
Set the application context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
application_context
|
IApplicationContext
|
The application context instance. |
required |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/post_processor.py
post_process(pod)
¶
Register commands from CLI controllers.
Scans the controller for methods decorated with @command and registers them as Typer commands. Automatically wraps async methods with run_async.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pod
|
object
|
The Pod to process, potentially a CLI controller. |
required |
Returns:
| Type | Description |
|---|---|
object
|
The Pod, with commands registered if it's a CLI controller. |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/post_processor.py
options: show_root_heading: false
Utilities¶
spakky.plugins.typer.utils.asyncio
¶
Asyncio utilities for Typer CLI integration.
Provides utilities for running async functions in synchronous contexts, enabling async command handlers in Typer CLI applications.
run_async(func)
¶
Convert an async function to a synchronous function.
Wraps an async function so it can be called synchronously by running it in an asyncio event loop. Useful for CLI commands that need to perform async operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[P, Awaitable[R]]
|
The async function to wrap. |
required |
Returns:
| Type | Description |
|---|---|
Callable[P, R]
|
A synchronous wrapper function that runs the async function. |
Source code in plugins/spakky-typer/src/spakky/plugins/typer/utils/asyncio.py
options: show_root_heading: false
spakky.plugins.typer.utils.casing
¶
String casing conversion utilities.
Provides utilities for converting between different string casing formats commonly used in CLI applications.
pascal_to_kebab(pascal_case)
¶
Convert PascalCase string to kebab-case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pascal_case
|
str
|
A string in PascalCase format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string converted to kebab-case format. |
Example
pascal_to_kebab("UserController") 'user-controller'
Source code in plugins/spakky-typer/src/spakky/plugins/typer/utils/casing.py
options: show_root_heading: false