Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hermes_cli/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ def generate_zsh(parser: argparse.ArgumentParser) -> str:
typeset -A opt_args

_arguments -C \\
'(-h --help){{-h,--help}}[Show help and exit]' \\
'(-V --version){{-V,--version}}[Show version and exit]' \\
'(-p --profile){{-p,--profile}}[Profile name]:profile:_hermes_profiles' \\
'(-h --help)'{{-h,--help}}'[Show help and exit]' \\
'(-V --version)'{{-V,--version}}'[Show version and exit]' \\
'(-p --profile)'{{-p,--profile}}'[Profile name]:profile:_hermes_profiles' \\
'1:command:->commands' \\
'*::arg:->args'

Expand Down
25 changes: 25 additions & 0 deletions tests/hermes_cli/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,31 @@ def test_nested_describe_blocks(self):
# gateway has subcommands so a _cmds array must be generated
assert "gateway_cmds" in out

def test_options_have_valid_arguments_syntax(self):
"""_arguments specs must have braces outside quotes for zsh to expand them.

Broken: '(-h --help){-h,--help}[Show help and exit]'
Correct: '(-h --help)'{-h,--help}'[Show help and exit]'
"""
out = generate_zsh(_make_parser())
assert "'(-h --help)'{-h,--help}'[Show help and exit]'" in out
assert "'(-V --version)'{-V,--version}'[Show version and exit]'" in out
assert "'(-p --profile)'{-p,--profile}'[Profile name]:profile:_hermes_profiles'" in out
# Ensure the old broken form is gone
assert "'(-h --help){-h,--help}[Show help and exit]'" not in out

def test_valid_zsh_syntax(self):
"""Script must pass zsh -n syntax check."""
out = generate_zsh(_make_parser())
with tempfile.NamedTemporaryFile(mode="w", suffix=".zsh", delete=False) as f:
f.write(out)
path = f.name
try:
result = subprocess.run(["zsh", "-n", path], capture_output=True)
assert result.returncode == 0, result.stderr.decode()
finally:
os.unlink(path)


# ---------------------------------------------------------------------------
# 4. Fish output
Expand Down