From ea18c0c40859de3f1a07e53eadbd3af8563e2c02 Mon Sep 17 00:00:00 2001 From: Vidit Patankar Date: Thu, 9 Jul 2026 16:57:59 +0530 Subject: [PATCH] fix: skip all hidden flags in shell completion, not just bool flags printFlagSuggestions only skipped hidden *BoolFlag values because it type-asserted to the concrete *BoolFlag type. Any other hidden flag (*StringFlag, *IntFlag, *DurationFlag, etc.) still leaked into shell completion output. Use the existing VisibleFlag interface (IsVisible) the same way visibleFlags and the flag-category code already do, so every hidden flag is skipped regardless of its concrete type. --- help.go | 2 +- help_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/help.go b/help.go index 4bedf87d5d..713afaeedb 100644 --- a/help.go +++ b/help.go @@ -216,7 +216,7 @@ func printFlagSuggestions(lastArg string, flags []Flag, writer io.Writer) { // Trim to handle both "-short" and "--long" flags. cur := strings.TrimLeft(lastArg, "-") for _, flag := range flags { - if bflag, ok := flag.(*BoolFlag); ok && bflag.Hidden { + if vf, ok := flag.(VisibleFlag); ok && !vf.IsVisible() { continue } diff --git a/help_test.go b/help_test.go index d3c831371d..c74e5494c1 100644 --- a/help_test.go +++ b/help_test.go @@ -1353,6 +1353,28 @@ func TestDefaultCompleteWithFlags(t *testing.T) { env: map[string]string{"SHELL": "bash"}, expected: "", }, + { + name: "typical-flag-suggestion-hidden-non-bool", + cmd: &Command{ + Flags: []Flag{ + &StringFlag{Name: "excellent", Hidden: true}, + &StringFlag{Name: "excitement"}, + }, + parent: &Command{ + Name: "cmd", + Flags: []Flag{ + &BoolFlag{Name: "happiness"}, + &Int64Flag{Name: "everybody-jump-on"}, + }, + Commands: []*Command{ + {Name: "putz"}, + }, + }, + }, + argv: []string{"cmd", "--e", completionFlag}, + env: map[string]string{"SHELL": "bash"}, + expected: "--excitement\n", + }, { name: "flag-suggestion-double-dash-shows-all-flags", cmd: &Command{