# groups

URL: /milo-cli/api/milo/groups/
Section: milo
Description: Nestable command groups for hierarchical CLI structures.

---

> For a complete page index, fetch /milo-cli/llms.txt.

Open LLM text
(/milo-cli/api/milo/groups/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fgroups%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fgroups%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fgroups%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fmilo-cli%2Fapi%2Fmilo%2Fgroups%2Findex.txt)

Module

#
`groups`

Nestable command groups for hierarchical CLI structures.

2Classes

## Classes

`GroupDef`

6

▼

Frozen snapshot of a command group.

Frozen snapshot of a command group.

#### Attributes

Name
Type
Description

`name`

`str`

—

`description`

`str`

—

`commands`

`dict[str, Any]`

—

`groups`

`dict[str, GroupDef]`

—

`aliases`

`tuple[str, ...]`

—

`hidden`

`bool`

—

`Group`

12

▼

A nestable command namespace.

Usage::

site = cli.group("site", description="Site operations")…

A nestable command namespace.

Usage::

```
site = cli.group("site", description="Site operations")

@site.command("build", description="Build the site")
def build(output: str = "_site") -> str: ...

config = site.group("config", description="Config management")

@config.command("show", description="Show merged config")
def show() -> dict: ...
```

CLI::

```
myapp site build --output _site
myapp site config show
```

#### Methods

`commands`

0

`dict[str, Any]`

▼

All registered commands in this group.

property

`def commands(self) -> dict[str, Any]`

##### Returns

`dict[str, Any]`

`groups`

0

`dict[str, Group]`

▼

All registered sub-groups.

property

`def groups(self) -> dict[str, Group]`

##### Returns

`dict[str, Group]`

`command`

8

`Callable`

▼

Register a function as a command within this group.

`def command(self, name: str, *, description: str = '', aliases: tuple[str, ...] | list[str] = (), tags: tuple[str, ...] | list[str] = (), hidden: bool = False, examples: tuple[dict[str, Any], ...] | list[dict[str, Any]] = (), confirm: str = '', display_result: bool = True) -> Callable`

##### Parameters

Name
Type
Description

`name`
`—`

`description`
`—`

Default:`''`

`aliases`
`—`

Default:`()`

`tags`
`—`

Default:`()`

`hidden`
`—`

Default:`False`

`examples`
`—`

Default:`()`

`confirm`
`—`

Default:`''`

`display_result`
`—`

Default:`True`

##### Returns

`Callable`

`lazy_command`

11

`Any`

▼

Register a lazy-loaded command within this group.

The handler module is not im…

`def lazy_command(self, name: str, import_path: str, *, description: str = '', schema: dict[str, Any] | None = None, aliases: tuple[str, ...] | list[str] = (), tags: tuple[str, ...] | list[str] = (), hidden: bool = False, examples: tuple[dict[str, Any], ...] | list[dict[str, Any]] = (), confirm: str = '', annotations: dict[str, Any] | None = None, display_result: bool = True) -> Any`

Register a lazy-loaded command within this group.

The handler module is not imported until the command is invoked.

##### Parameters

Name
Type
Description

`name`
`—`

`import_path`
`—`

`description`
`—`

Default:`''`

`schema`
`—`

Default:`None`

`aliases`
`—`

Default:`()`

`tags`
`—`

Default:`()`

`hidden`
`—`

Default:`False`

`examples`
`—`

Default:`()`

`confirm`
`—`

Default:`''`

`annotations`
`—`

Default:`None`

`display_result`
`—`

Default:`True`

##### Returns

`Any`

`group`

4

`Group`

▼

Create and register a sub-group. Returns it for chaining.

`def group(self, name: str, *, description: str = '', aliases: tuple[str, ...] | list[str] = (), hidden: bool = False) -> Group`

##### Parameters

Name
Type
Description

`name`
`—`

`description`
`—`

Default:`''`

`aliases`
`—`

Default:`()`

`hidden`
`—`

Default:`False`

##### Returns

`Group`

`add_group`

1

▼

Add an existing Group as a sub-group.

`def add_group(self, group: Group) -> None`

##### Parameters

Name
Type
Description

`group`
`—`

`get_command`

1

`Any | None`

▼

Look up a command by name or alias within this group.

`def get_command(self, name: str) -> Any | None`

##### Parameters

Name
Type
Description

`name`
`—`

##### Returns

`Any | None`

`get_group`

1

`Group | None`

▼

Look up a sub-group by name or alias.

`def get_group(self, name: str) -> Group | None`

##### Parameters

Name
Type
Description

`name`
`—`

##### Returns

`Group | None`

`to_def`

0

`GroupDef`

▼

Freeze into immutable GroupDef tree.

`def to_def(self) -> GroupDef`

##### Returns

`GroupDef`

`format_help`

1

`str`

▼

Render help from this group's command/group registries.

Writes rendered help t…

`def format_help(self, prog_prefix: str = '') -> str`

Render help from this group's command/group registries.

Writes rendered help to stdout and returns the output string.

##### Parameters

Name
Type
Description

`prog_prefix`
`—`

Default:`''`

##### Returns

`str`

`walk_commands`

1

▼

Yield (dotted_path, CommandDef) for all commands in this tree.

`def walk_commands(self, prefix: str = '')`

##### Parameters

Name
Type
Description

`prefix`
`—`

Default:`''`

Internal Methods
1

▼

`__init__`

5

▼

`def __init__(self, name: str, *, description: str = '', aliases: tuple[str, ...] | list[str] = (), hidden: bool = False, on_change: Callable[[], None] | None = None) -> None`

##### Parameters

Name
Type
Description

`name`
`—`

`description`
`—`

Default:`''`

`aliases`
`—`

Default:`()`

`hidden`
`—`

Default:`False`

`on_change`
`—`

Default:`None`
