Skip to content

Commit d6372ae

Browse files
authored
fix: root cmd completions (#22)
* fix root cmd completions * update
1 parent 933535a commit d6372ae

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,21 +337,24 @@ export class Completion {
337337
previousArgs: string[],
338338
toComplete: string
339339
) {
340-
const commandParts = [...previousArgs];
340+
const commandParts = [...previousArgs].filter(Boolean);
341341

342342
for (const [k, command] of this.commands) {
343343
if (k === '') continue;
344+
344345
const parts = k.split(' ');
345-
let match = true;
346346

347+
let match = true;
347348
let i = 0;
349+
348350
while (i < commandParts.length) {
349351
if (parts[i] !== commandParts[i]) {
350352
match = false;
351353
break;
352354
}
353355
i++;
354356
}
357+
355358
if (match && parts[i]?.startsWith(toComplete)) {
356359
this.completions.push({
357360
value: parts[i],

0 commit comments

Comments
 (0)