|
8 | 8 | import subprocess
|
9 | 9 |
|
10 | 10 | from cleo import helpers
|
| 11 | +from cleo._compat import shell_quote |
11 | 12 | from cleo.commands.command import Command
|
12 | 13 | from cleo.commands.completions.templates import TEMPLATES
|
13 | 14 |
|
@@ -156,13 +157,14 @@ def render_bash(self) -> str:
|
156 | 157 | for cmd in sorted(self.application.all().values(), key=lambda c: c.name or ""):
|
157 | 158 | if cmd.hidden or not cmd.enabled or not cmd.name:
|
158 | 159 | continue
|
159 |
| - cmds.append(cmd.name) |
| 160 | + command_name = shell_quote(cmd.name) if " " in cmd.name else cmd.name |
| 161 | + cmds.append(command_name) |
160 | 162 | options = " ".join(
|
161 | 163 | f"--{opt.name}".replace(":", "\\:")
|
162 | 164 | for opt in sorted(cmd.definition.options, key=lambda o: o.name)
|
163 | 165 | )
|
164 | 166 | cmds_opts += [
|
165 |
| - f" ({cmd.name})", |
| 167 | + f" ({command_name})", |
166 | 168 | f' opts="${{opts}} {options}"',
|
167 | 169 | " ;;",
|
168 | 170 | "", # newline
|
@@ -200,13 +202,14 @@ def sanitize(s: str) -> str:
|
200 | 202 | for cmd in sorted(self.application.all().values(), key=lambda c: c.name or ""):
|
201 | 203 | if cmd.hidden or not cmd.enabled or not cmd.name:
|
202 | 204 | continue
|
203 |
| - cmds.append(self._zsh_describe(cmd.name, sanitize(cmd.description))) |
| 205 | + command_name = shell_quote(cmd.name) if " " in cmd.name else cmd.name |
| 206 | + cmds.append(self._zsh_describe(command_name, sanitize(cmd.description))) |
204 | 207 | options = " ".join(
|
205 | 208 | self._zsh_describe(f"--{opt.name}", sanitize(opt.description))
|
206 | 209 | for opt in sorted(cmd.definition.options, key=lambda o: o.name)
|
207 | 210 | )
|
208 | 211 | cmds_opts += [
|
209 |
| - f" ({cmd.name})", |
| 212 | + f" ({command_name})", |
210 | 213 | f" opts+=({options})",
|
211 | 214 | " ;;",
|
212 | 215 | "", # newline
|
@@ -243,21 +246,22 @@ def sanitize(s: str) -> str:
|
243 | 246 | for cmd in sorted(self.application.all().values(), key=lambda c: c.name or ""):
|
244 | 247 | if cmd.hidden or not cmd.enabled or not cmd.name:
|
245 | 248 | continue
|
| 249 | + command_name = shell_quote(cmd.name) if " " in cmd.name else cmd.name |
246 | 250 | cmds.append(
|
247 | 251 | f"complete -c {script_name} -f -n '__fish{function}_no_subcommand' "
|
248 |
| - f"-a {cmd.name} -d '{sanitize(cmd.description)}'" |
| 252 | + f"-a {command_name} -d '{sanitize(cmd.description)}'" |
249 | 253 | )
|
250 | 254 | cmds_opts += [
|
251 |
| - f"# {cmd.name}", |
| 255 | + f"# {command_name}", |
252 | 256 | *[
|
253 | 257 | f"complete -c {script_name} -A "
|
254 |
| - f"-n '__fish_seen_subcommand_from {cmd.name}' " |
| 258 | + f"-n '__fish_seen_subcommand_from {command_name}' " |
255 | 259 | f"-l {opt.name} -d '{sanitize(opt.description)}'"
|
256 | 260 | for opt in sorted(cmd.definition.options, key=lambda o: o.name)
|
257 | 261 | ],
|
258 | 262 | "", # newline
|
259 | 263 | ]
|
260 |
| - cmds_names.append(cmd.name) |
| 264 | + cmds_names.append(command_name) |
261 | 265 |
|
262 | 266 | return TEMPLATES["fish"] % {
|
263 | 267 | "script_name": script_name,
|
|
0 commit comments