From 9d0c9e3f28e621bf2e00d7e09dea9ae7b57c13d4 Mon Sep 17 00:00:00 2001 From: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> Date: Tue, 6 Oct 2026 00:11:01 +0530 Subject: [PATCH] fix(autocomplete): filter out hidden commands when args is empty --- internal/autocomplete/autocomplete.go | 4 +++- internal/autocomplete/autocomplete_test.go | 15 +++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/autocomplete/autocomplete.go b/internal/autocomplete/autocomplete.go index 97fe1a8..927e2e2 100644 --- a/internal/autocomplete/autocomplete.go +++ b/internal/autocomplete/autocomplete.go @@ -216,7 +216,9 @@ func getAllPossibleCompletions(completionStyle CompletionStyle, root *cli.Comman completions := make([]ShellCompletion, 0) if len(args) == 0 { for _, child := range root.Commands { - completions = builder.createFromCommand("", child, completions) + if !child.Hidden { + completions = builder.createFromCommand("", child, completions) + } } return CompletionResult{Completions: completions, Behavior: ShellCompletionBehaviorDefault} } diff --git a/internal/autocomplete/autocomplete_test.go b/internal/autocomplete/autocomplete_test.go index 2338924..5aba2cf 100644 --- a/internal/autocomplete/autocomplete_test.go +++ b/internal/autocomplete/autocomplete_test.go @@ -56,10 +56,17 @@ func TestGetCompletions_HiddenCommand(t *testing.T) { }, } - result := GetCompletions(CompletionStyleBash, root, []string{""}) - - assert.Len(t, result.Completions, 1) - assert.Equal(t, "visible", result.Completions[0].Name) + t.Run("with empty string prefix", func(t *testing.T) { + result := GetCompletions(CompletionStyleBash, root, []string{""}) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "visible", result.Completions[0].Name) + }) + + t.Run("with empty args slice", func(t *testing.T) { + result := GetCompletions(CompletionStyleBash, root, []string{}) + assert.Len(t, result.Completions, 1) + assert.Equal(t, "visible", result.Completions[0].Name) + }) } func TestGetCompletions_NestedSubcommand(t *testing.T) {