From d6372ae467fac2e663ecfc81976c29d19ce2535b Mon Sep 17 00:00:00 2001 From: AmirHossein Sakhravi Date: Tue, 29 Apr 2025 00:32:27 +0330 Subject: [PATCH] fix: root cmd completions (#22) * fix root cmd completions * update --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 35d9b47..5e0286a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -337,14 +337,16 @@ export class Completion { previousArgs: string[], toComplete: string ) { - const commandParts = [...previousArgs]; + const commandParts = [...previousArgs].filter(Boolean); for (const [k, command] of this.commands) { if (k === '') continue; + const parts = k.split(' '); - let match = true; + let match = true; let i = 0; + while (i < commandParts.length) { if (parts[i] !== commandParts[i]) { match = false; @@ -352,6 +354,7 @@ export class Completion { } i++; } + if (match && parts[i]?.startsWith(toComplete)) { this.completions.push({ value: parts[i], -- 2.51.2