nested_commands
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.1.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.1.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
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 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |