Feat/group feature#12
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces hierarchical command grouping to cmdcraft via a new CommandGroup class, enabling spaced command paths (e.g. motor axis move). It also reworks the BasePrompter registry/resolution flow, extends the prompt-toolkit Prompter to build nested completers, hides API docstring sections from interpreter help, and ships an example plus refreshed documentation and tests.
Changes:
- Add
CommandGroupwith path-awareregister_group/register_command/resolve/command_pathsand integrate it intoBasePrompteras the root registry, plus grouped-help formatting and conflict detection. - Build the prompt-toolkit
NestedCompleterrecursively from the group tree so grouped paths complete correctly. - Expand tests for grouped paths, nested completion, help behavior, and conflict errors; add a runnable grouped-command example and update docs/README.
Reviewed changes
Copilot reviewed 11 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/cmdcraft/group.py | New CommandGroup plus path helpers powering registration and resolution. |
| src/cmdcraft/base.py | Route registration/resolution through _root_group; rework interpret and help to handle paths and group help. |
| src/cmdcraft/prompter.py | Recursive nested completer from group tree, updated docstrings/license header. |
| src/cmdcraft/init.py | Export CommandGroup, bump version to 0.0.8, add license header. |
| test/test_base.py | Coverage for grouped command paths, group/command conflicts, and help filtering. |
| test/test_prompter.py | Coverage for nested completion on grouped command paths. |
| examples/group_commands.py | New runnable example demonstrating grouped command registration. |
| examples/tmp.py | Removes stale temporary example. |
| docs/pages/howto/crafting.rst | New "Command Grouping" section with usage example (indentation issues flagged). |
| docs/pages/documentation.rst | Adds cmdcraft.group API reference. |
| README.rst | Mentions nested command groups feature. |
| .gitignore | Adds eggs, .github/, .vscode/ (the .github/ entry is flagged). |
Comments suppressed due to low confidence (1)
docs/pages/howto/crafting.rst:79
- The code block in this documentation section has inconsistent indentation that makes it invalid Python. Inside
async def main(), the body starts at 8 spaces (prompt = Prompter()) but the subsequent statements use 6 spaces (project = prompt.register_group(...),config = ..., etc.), andawait prompt.run()reverts to 8 spaces. A user copy-pasting this snippet will get anIndentationError. Please normalize the indentation of all statements insidemain()to the same level (4 spaces underasync def main()is the convention used by the rest of the example).
async def main() -> None:
prompt = Prompter()
project = prompt.register_group("project", doc="Project commands.")
project.register_command(start)
project.register_command(status)
config = prompt.register_group(
"project config",
doc="Project configuration commands.",
)
config.register_command(show)
prompt.register_command(set_value, alias="project config set")
profiles = prompt.register_group(
"project profile",
doc="Project profile commands.",
)
profiles.register_command(list_profiles, alias="list")
await prompt.run()
asyncio.run(main())
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+43
to
+75
| print("project started") | ||
|
|
||
| async def status() -> None: | ||
| print("project status shown") | ||
|
|
||
| async def show() -> None: | ||
| print("project configuration shown") | ||
|
|
||
| async def set_value(key: str, value: str) -> None: | ||
| print(f"project configuration updated: {key}={value}") | ||
|
|
||
| async def list_profiles() -> None: | ||
| print("profiles: dev, test, prod") | ||
|
|
||
| async def main() -> None: | ||
| prompt = Prompter() | ||
|
|
||
| project = prompt.register_group("project", doc="Project commands.") | ||
| project.register_command(start) | ||
| project.register_command(status) | ||
|
|
||
| config = prompt.register_group( | ||
| "project config", | ||
| doc="Project configuration commands.", | ||
| ) | ||
| config.register_command(show) | ||
| prompt.register_command(set_value, alias="project config set") | ||
|
|
||
| profiles = prompt.register_group( | ||
| "project profile", | ||
| doc="Project profile commands.", | ||
| ) | ||
| profiles.register_command(list_profiles, alias="list") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add hierarchical command grouping to the prompter, improve runtime stability around interrupts and help output, and expand the examples, tests, and documentation so grouped command paths are supported and documented end to end.
What Changed
CommandGroup, including nested path registration, grouped command resolution, grouped help output, and nested prompt completions.motor startandmotor axis move, with conflict checks when a command or group path is already occupied.Ctrl+Cwith graceful shutdown on first interrupt and forced exit on the second interrupt.Args:andReturns:.Type of Change
Validation
./tools/format.shsource .venv/bin/activate && ./tools/lint.sh --changedsource .venv/bin/activate && pytest -qsource .venv/bin/activate && python -m sphinx -b html docs docs/_build/htmlsource .venv/bin/activate && python -m buildNotes for Reviewers
BasePrompter/CommandGroup, the nested completer wiring inPrompter, and the new regression coverage around grouped paths and interrupt handling._staticdocs path and theprompt_toolkitforward-reference warning fromsphinx_autodoc_typehints.