spakky-typer¶
Typer CLI 통합 — CLI 컨트롤러 자동 등록
메인¶
spakky.plugins.typer.main
¶
Plugin initialization for Typer CLI integration.
Registers post-processor for automatic CLI command registration from @CliController decorated classes.
typer_app()
¶
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
스테레오타입¶
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
|
type[T]
|
The class to decorate. |
required |
Returns:
| Type | Description |
|---|---|
type[T]
|
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[..., T]], Callable[..., T]]
|
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
후처리기¶
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
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
options: show_root_heading: false
spakky.plugins.typer.actuator
¶
Typer command adapter for actuator status output.
ActuatorTyperConfig()
¶
ActuatorTyperCommandPostProcessor(app, config)
¶
Bases: IPostProcessor, IContainerAware, IApplicationContextAware
Register actuator commands when the actuator core service is loaded.
Initialize with Typer app and actuator command configuration.
Source code in plugins/spakky-typer/src/spakky/plugins/typer/actuator.py
set_container(container)
¶
set_application_context(application_context)
¶
Set the application context used to clear CLI invocation scope.
post_process(pod)
¶
Register actuator command group after actuator service is available.
Source code in plugins/spakky-typer/src/spakky/plugins/typer/actuator.py
options: show_root_heading: false
유틸리티¶
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