core
core
Composable, transportable command-registry core for interactive CLIs.
CommandError
Bases: Exception
Base error for command dispatch or execution failures.
UsageError
Bases: CommandError
Raise when a command is invoked with missing or invalid arguments.
UnknownCommandError
Bases: CommandError
Raise when a token matches neither a child group nor a local command.
Command
dataclass
Command(
name: str,
handler: CommandHandler,
usage: str = "",
help: str = "",
completions: Callable[[], list[str]] | None = None,
)
A single named leaf command in a command group.
CommandGroup
A composable namespace of commands and nested child groups.
Initialise an empty command group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The group's own name. |
required |
help
|
str
|
Short description of the group. |
''
|
Source code in src/applied_motion/cli/compose/core.py
add_command
add_child
Mount a child group under a name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
CommandGroup
|
The child group to mount. |
required |
name
|
str | None
|
Mount key. Defaults to the child group's name. |
None
|
Returns:
| Type | Description |
|---|---|
CommandGroup
|
The mounted child group. |
Source code in src/applied_motion/cli/compose/core.py
dispatch
Route a token sequence to a child group or a local command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tokens
|
Sequence[str]
|
The whitespace-split command line. |
required |
Raises:
| Type | Description |
|---|---|
UnknownCommandError
|
If no matching child or command is found. |
Source code in src/applied_motion/cli/compose/core.py
iter_paths
Yield the fully-qualified path of every command in the tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
Sequence[str]
|
Internal prefix accumulator. |
()
|
Yields:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuples of namespace names ending in a command name. |
Source code in src/applied_motion/cli/compose/core.py
format_help
Build indented help lines for this group and all descendants.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
Current indentation depth. |
0
|
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of formatted help lines. |