Skip to content

Commit ec14c7e

Browse files
committed
chore: update
1 parent 85a9aed commit ec14c7e

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

src/autocomplete/zsh.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,8 @@ _${this.config.bin}
205205
const cflags = this.commands.find(c => c.id === id)?.flags
206206

207207
if (cflags) {
208-
valuesBlock += ' \\'
209-
this.genZshFlagArguments(cflags)
210-
.split('\n')
211-
.forEach(f => {
212-
valuesBlock += `\n ${f}`
213-
})
208+
// eslint-disable-next-line no-template-curly-in-string
209+
valuesBlock += ' \\\n "${flags[@]}"'
214210
}
215211
}
216212

@@ -234,7 +230,7 @@ _${this.config.bin}
234230
summary: t.description,
235231
})
236232

237-
argsBlock += util.format('"%s")\n %s\n ;;', subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
233+
argsBlock += util.format('\n "%s")\n %s\n ;;', subArg, `_${this.config.bin}_${underscoreSepId}_${subArg}`)
238234
})
239235

240236
for (const c of this.commands.filter(c => c.id.startsWith(id + ':') && c.id.split(':').length === depth + 1)) {
@@ -246,30 +242,50 @@ _${this.config.bin}
246242
summary: c.summary,
247243
})
248244

249-
argsBlock += util.format('"%s")\n %s\n ;;', subArg, this.genZshFlagArgumentsBlock(c.flags))
245+
const block = this.genZshFlagArgumentsBlock(c.flags)
246+
argsBlock += util.format('\n "%s")\n %s\n ;;', subArg, block)
250247
}
251248
}
252249

253-
const topicCompFunc =
254-
`_${this.config.bin}_${underscoreSepId}() {
250+
let flags = ''
251+
252+
if (id) {
253+
const cflags = this.commands.find(c => c.id === id)?.flags
254+
255+
if (cflags) {
256+
flags += '\n';
257+
(this.genZshFlagArguments(cflags)).split('\n').forEach(f => {
258+
flags += ` ${f}\n`
259+
})
260+
flags += ' '
261+
}
262+
}
263+
264+
const topicCompFunc = `_${this.config.bin}_${underscoreSepId}() {
255265
local context state state_descr line
256266
typeset -A opt_args
257267
258268
_arguments -C "1: :->cmds" "*::arg:->args"
259269
270+
local -a flags=(%s)
271+
260272
case "$state" in
261273
cmds)
262274
%s
263275
;;
264276
args)
265-
case $line[1] in
266-
%s
277+
case $line[1] in%s
278+
*)
279+
_arguments -S \\
280+
"\${flags[@]}"
281+
;;
267282
esac
268283
;;
269284
esac
270285
}
271286
`
272-
return util.format(topicCompFunc, this.genZshValuesBlock({id, subArgs}), argsBlock)
287+
288+
return util.format(topicCompFunc, flags, this.genZshValuesBlock({id, subArgs}), argsBlock)
273289
}
274290

275291
private getCoTopics(): string[] {
@@ -287,7 +303,8 @@ _${this.config.bin}
287303
}
288304

289305
private getTopics(): Topic[] {
290-
const topics = this.config.topics.filter((topic: Interfaces.Topic) => {
306+
const topics = this.config.topics
307+
.filter((topic: Interfaces.Topic) => {
291308
// it is assumed a topic has a child if it has children
292309
const hasChild = this.config.topics.some(subTopic => subTopic.name.includes(`${topic.name}:`))
293310
return hasChild
@@ -359,4 +376,3 @@ _${this.config.bin}
359376
return cmds
360377
}
361378
}
362-

test/autocomplete/zsh.test.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ _test-cli_app() {
186186
187187
_arguments -C "1: :->cmds" "*::arg:->args"
188188
189+
local -a flags=()
190+
189191
case "$state" in
190192
cmds)
191193
_values "completions" \\
@@ -196,6 +198,10 @@ _test-cli_app() {
196198
"execute")
197199
_test-cli_app_execute
198200
;;
201+
*)
202+
_arguments -S \\
203+
"\${flags[@]}"
204+
;;
199205
esac
200206
;;
201207
esac
@@ -207,6 +213,8 @@ _test-cli_app_execute() {
207213
208214
_arguments -C "1: :->cmds" "*::arg:->args"
209215
216+
local -a flags=()
217+
210218
case "$state" in
211219
cmds)
212220
_values "completions" \\
@@ -219,6 +227,10 @@ _test-cli_app_execute() {
219227
--help"[Show help for command]" \\
220228
"*: :_files"
221229
;;
230+
*)
231+
_arguments -S \\
232+
"\${flags[@]}"
233+
;;
222234
esac
223235
;;
224236
esac
@@ -230,16 +242,20 @@ _test-cli_deploy() {
230242
231243
_arguments -C "1: :->cmds" "*::arg:->args"
232244
245+
local -a flags=(
246+
"*"{-m,--metadata}"[]:file:_files" \\
247+
"(-a --api-version)"{-a,--api-version}"[]:file:_files" \\
248+
--json"[Format output as json.]" \\
249+
"(-i --ignore-errors)"{-i,--ignore-errors}"[Ignore errors.]" \\
250+
--help"[Show help for command]" \\
251+
"*: :_files"
252+
)
253+
233254
case "$state" in
234255
cmds)
235256
_values "completions" \\
236257
"functions[Deploy a function.]" \\
237-
"*"{-m,--metadata}"[]:file:_files" \\
238-
"(-a --api-version)"{-a,--api-version}"[]:file:_files" \\
239-
--json"[Format output as json.]" \\
240-
"(-i --ignore-errors)"{-i,--ignore-errors}"[Ignore errors.]" \\
241-
--help"[Show help for command]" \\
242-
"*: :_files"
258+
"\${flags[@]}"
243259
;;
244260
args)
245261
case $line[1] in
@@ -249,6 +265,10 @@ _test-cli_deploy() {
249265
--help"[Show help for command]" \\
250266
"*: :_files"
251267
;;
268+
*)
269+
_arguments -S \\
270+
"\${flags[@]}"
271+
;;
252272
esac
253273
;;
254274
esac

0 commit comments

Comments
 (0)