nested_commands
๐ค AI-Generated Content
This documentation was generated with AI assistance and is still being audited. Some, or potentially a lot, of this information may be inaccurate. Learn more.
wrknv.cli.nested_commands
¶
Enhanced command registration with nested group support.
This module extends the Foundation Hub to support nested command groups,
allowing natural CLI structures like wrknv container status instead of
wrknv container-status.
Classes¶
CommandGroup
dataclass
¶
CommandGroup(
name: str,
description: str | None = None,
commands: dict[
str, CommandInfo | CommandGroup
] = dict(),
parent: CommandGroup | None = None,
hidden: bool = False,
)
Represents a command group that can contain subcommands.
Functions¶
add_command
¶
get_command
¶
Get a command by path (e.g., ['container', 'status']).
Source code in wrknv/cli/nested_commands.py
to_click_group
¶
Convert this command group to a Click group.
Source code in wrknv/cli/nested_commands.py
NestedCommandRegistry
¶
Registry that supports nested command groups.
Source code in wrknv/cli/nested_commands.py
Functions¶
get_command
¶
register_command
¶
register_command(
name: str,
func: Callable[..., Any] | None = None,
description: str | None = None,
group: bool = False,
parent: str | None = None,
hidden: bool = False,
aliases: list[str] | None = None,
) -> None
Register a command or command group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Command name (can include spaces for nested commands) |
required |
func
|
Callable[..., Any] | None
|
Function to execute (None for groups) |
None
|
description
|
str | None
|
Command/group description |
None
|
group
|
bool
|
Whether this is a command group |
False
|
parent
|
str | None
|
Parent group name (alternative to space-separated name) |
None
|
hidden
|
bool
|
Whether to hide from help |
False
|
aliases
|
list[str] | None
|
Command aliases |
None
|
Source code in wrknv/cli/nested_commands.py
Functions¶
create_nested_cli
¶
create_nested_cli(
name: str = "wrknv",
version: str = "0.3.0",
help: str | None = None,
) -> click.Group
Create a CLI with nested command groups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
CLI name |
'wrknv'
|
version
|
str
|
CLI version |
'0.3.0'
|
help
|
str | None
|
CLI help text |
None
|
Returns:
| Type | Description |
|---|---|
Group
|
Click Group with nested commands |
Source code in wrknv/cli/nested_commands.py
get_nested_registry
¶
register_nested_command
¶
register_nested_command(
name: str,
*,
description: str | None = None,
group: bool = False,
parent: str | None = None,
hidden: bool = False,
aliases: list[str] | None = None,
) -> Callable[[F], F]
Register a command with support for nested groups.
Examples:
Register a simple command¶
@register_nested_command("status") def status(): pass
Register a command group¶
@register_nested_command("container", group=True) def container_group(): pass
Register a subcommand (two ways)¶
@register_nested_command("container status") def container_status(): pass
Or using parent parameter¶
@register_nested_command("status", parent="container") def container_status(): pass
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Command name (can be space-separated for nesting) |
required |
description
|
str | None
|
Command description |
None
|
group
|
bool
|
Whether this is a command group |
False
|
parent
|
str | None
|
Parent group (alternative to space-separated name) |
None
|
hidden
|
bool
|
Hide from help |
False
|
aliases
|
list[str] | None
|
Command aliases |
None
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
Decorator function |
Source code in wrknv/cli/nested_commands.py
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 | |