Skip to content

Commit 018710f

Browse files
fix: hide GLOBAL OPTIONS in completion command help
The completion command ignores global flags by design, so displaying them in --help output is misleading. Return nil from VisiblePersistentFlags() when isCompletionCommand is true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e8afe93 commit 018710f

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

command.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ func (cmd *Command) appendFlag(fl Flag) {
303303

304304
// VisiblePersistentFlags returns a slice of [LocalFlag] with Persistent=true and Hidden=false.
305305
func (cmd *Command) VisiblePersistentFlags() []Flag {
306+
if cmd.isCompletionCommand {
307+
return nil
308+
}
306309
var flags []Flag
307310
for _, fl := range cmd.Root().Flags {
308311
pfl, ok := fl.(LocalFlag)

completion_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestCompletionHelp(t *testing.T) {
5252

5353
r.NoError(cmd.Run(buildTestContext(t), test.args))
5454
r.Contains(out.String(), "USAGE")
55+
r.NotContains(out.String(), "GLOBAL OPTIONS")
5556
})
5657
}
5758
}

0 commit comments

Comments
 (0)