From b2cbc9725bc246a76dda160b6bce80873ef7c85b Mon Sep 17 00:00:00 2001 From: Pavel Sapezhka Date: Thu, 28 Mar 2024 16:24:39 +0200 Subject: [PATCH] Do not quote spaced commands in ZSH (#360) --- news/360.bugfix.md | 1 + src/cleo/commands/completions_command.py | 5 ++--- tests/commands/completion/fixtures/zsh.txt | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) create mode 100644 news/360.bugfix.md diff --git a/news/360.bugfix.md b/news/360.bugfix.md new file mode 100644 index 00000000..da53fa14 --- /dev/null +++ b/news/360.bugfix.md @@ -0,0 +1 @@ +Disabled quoting multiple-word completion tokens in ZSH diff --git a/src/cleo/commands/completions_command.py b/src/cleo/commands/completions_command.py index 11735cde..598dca6e 100644 --- a/src/cleo/commands/completions_command.py +++ b/src/cleo/commands/completions_command.py @@ -234,14 +234,13 @@ def sanitize(s: str) -> str: for cmd in sorted(self.application.all().values(), key=lambda c: c.name or ""): if cmd.hidden or not (cmd.enabled and cmd.name): continue - command_name = shell_quote(cmd.name) if " " in cmd.name else cmd.name - cmds.append(self._zsh_describe(command_name, sanitize(cmd.description))) + cmds.append(self._zsh_describe(cmd.name, sanitize(cmd.description))) options = " ".join( self._zsh_describe(f"--{opt.name}", sanitize(opt.description)) for opt in sorted(cmd.definition.options, key=lambda o: o.name) ) cmds_opts += [ - f" ({command_name})", + f" ({cmd.name})", f" opts+=({options})", " ;;", "", # newline diff --git a/tests/commands/completion/fixtures/zsh.txt b/tests/commands/completion/fixtures/zsh.txt index df9f9266..3041136b 100644 --- a/tests/commands/completion/fixtures/zsh.txt +++ b/tests/commands/completion/fixtures/zsh.txt @@ -21,7 +21,7 @@ _my_function() opts+=("--ansi:Force ANSI output." "--help:Display help for the given command. When no command is given display help for the list command." "--no-ansi:Disable ANSI output." "--no-interaction:Do not ask any interactive question." "--quiet:Do not output any message." "--verbose:Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug." "--version:Display this application version.") elif [[ $cur == $com ]]; then state="command" - coms+=("command\:with\:colons:Test." "hello:Complete me please." "help:Displays help for a command." "list:Lists commands." "'spaced command':Command with space in name.") + coms+=("command\:with\:colons:Test." "hello:Complete me please." "help:Displays help for a command." "list:Lists commands." "spaced command:Command with space in name.") fi case $state in @@ -47,7 +47,7 @@ _my_function() opts+=() ;; - ('spaced command') + (spaced command) opts+=("--goodbye") ;;