diff --git a/hermes_cli/completion.py b/hermes_cli/completion.py index 591ffecc62f..efedad5eb78 100644 --- a/hermes_cli/completion.py +++ b/hermes_cli/completion.py @@ -216,9 +216,9 @@ _hermes() {{ typeset -A opt_args _arguments -C \\ - '(-)'{{-h,--help}}'[Show help and exit]' \\ - '(-)'{{-V,--version}}'[Show version and exit]' \\ - '(-)'{{-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' @@ -238,7 +238,7 @@ _hermes() {{ esac }} -_hermes "$@" +compdef _hermes hermes """ diff --git a/tests/hermes_cli/test_completion.py b/tests/hermes_cli/test_completion.py index 20bde059f2e..1e85653290a 100644 --- a/tests/hermes_cli/test_completion.py +++ b/tests/hermes_cli/test_completion.py @@ -140,6 +140,36 @@ class TestGenerateZsh: # gateway has subcommands so a _cmds array must be generated assert "gateway_cmds" in out + def test_registers_compdef_instead_of_invoking_completion_function(self): + out = generate_zsh(_make_parser()) + assert 'compdef _hermes hermes' in out + assert '_hermes "$@"' not in out + + def test_uses_valid_zsh_arguments_alias_syntax(self): + 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 + assert "'(-h --help){-h,--help}[Show help and exit]'" not in out + + def test_valid_zsh_syntax_when_sourced_after_compinit(self): + if not shutil.which("zsh"): + pytest.skip("zsh not installed") + 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", "-fc", f"autoload -Uz compinit && compinit; source {path}"], + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stderr + assert result.stderr == "" + finally: + os.unlink(path) + # --------------------------------------------------------------------------- # 4. Fish output