mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-29 06:31:32 +00:00
feat(cli): add dynamic shell completion for bash, zsh, and fish
Replaces the hardcoded completion stubs in profiles.py with a dynamic generator that walks the live argparse parser tree at runtime. - New hermes_cli/completion.py: _walk() recursively extracts all subcommands and flags; generate_bash/zsh/fish() produce complete scripts with nested subcommand support - cmd_completion now accepts the parser via closure so completions always reflect the actual registered commands (including plugin- registered ones like honcho) - completion subcommand now accepts bash | zsh | fish (fish requested in issue comments) - Fix _SUBCOMMANDS set: add honcho, claw, plugins, acp, webhook, memory, dump, debug, backup, import, completion, logs so that multi-word session names after -c/-r are not broken by these commands - Add tests/hermes_cli/test_completion.py: 17 tests covering parser extraction, alias deduplication, bash/zsh/fish output content, bash syntax validation, fish syntax validation, and subcommand drift prevention Tested on Linux (Arch). bash and fish completion verified live. zsh script passes syntax check (zsh not installed on test machine). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b21b3bfd68
commit
a686dbdd26
3 changed files with 432 additions and 8 deletions
|
|
@ -4124,6 +4124,8 @@ def _coalesce_session_name_args(argv: list) -> list:
|
|||
"status", "cron", "doctor", "config", "pairing", "skills", "tools",
|
||||
"mcp", "sessions", "insights", "version", "update", "uninstall",
|
||||
"profile", "dashboard",
|
||||
"honcho", "claw", "plugins", "acp",
|
||||
"webhook", "memory", "dump", "debug", "backup", "import", "completion", "logs",
|
||||
}
|
||||
_SESSION_FLAGS = {"-c", "--continue", "-r", "--resume"}
|
||||
|
||||
|
|
@ -4422,14 +4424,24 @@ def cmd_dashboard(args):
|
|||
)
|
||||
|
||||
|
||||
def cmd_completion(args):
|
||||
def cmd_completion(args, parser=None):
|
||||
"""Print shell completion script."""
|
||||
from hermes_cli.profiles import generate_bash_completion, generate_zsh_completion
|
||||
from hermes_cli.completion import generate_bash, generate_zsh, generate_fish
|
||||
shell = getattr(args, "shell", "bash")
|
||||
if shell == "zsh":
|
||||
print(generate_zsh_completion())
|
||||
if parser is not None:
|
||||
if shell == "zsh":
|
||||
print(generate_zsh(parser))
|
||||
elif shell == "fish":
|
||||
print(generate_fish(parser))
|
||||
else:
|
||||
print(generate_bash(parser))
|
||||
else:
|
||||
print(generate_bash_completion())
|
||||
# Fallback: parser not available (e.g. called outside main())
|
||||
from hermes_cli.profiles import generate_bash_completion, generate_zsh_completion
|
||||
if shell == "zsh":
|
||||
print(generate_zsh_completion())
|
||||
else:
|
||||
print(generate_bash_completion())
|
||||
|
||||
|
||||
def cmd_logs(args):
|
||||
|
|
@ -5909,13 +5921,13 @@ Examples:
|
|||
# =========================================================================
|
||||
completion_parser = subparsers.add_parser(
|
||||
"completion",
|
||||
help="Print shell completion script (bash or zsh)",
|
||||
help="Print shell completion script (bash, zsh, or fish)",
|
||||
)
|
||||
completion_parser.add_argument(
|
||||
"shell", nargs="?", default="bash", choices=["bash", "zsh"],
|
||||
"shell", nargs="?", default="bash", choices=["bash", "zsh", "fish"],
|
||||
help="Shell type (default: bash)",
|
||||
)
|
||||
completion_parser.set_defaults(func=cmd_completion)
|
||||
completion_parser.set_defaults(func=lambda args: cmd_completion(args, parser))
|
||||
|
||||
# =========================================================================
|
||||
# dashboard command
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue