Skip to content

Commit 3d1d7ad

Browse files
ffantl-ldclaude
andcommitted
refactor: scope the access-token required-flag skip per command
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 3ffac48 commit 3d1d7ad

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

cmd/root.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,10 @@ func NewRootCommand(
126126
Long: "LaunchDarkly CLI to control your feature flags",
127127
Version: version,
128128
PersistentPreRun: func(cmd *cobra.Command, args []string) {
129-
// disable required flags when running certain commands
129+
// Skip the global --access-token required-flag check for commands
130+
// that don't need an API token. We clear the annotation on the
131+
// specific flag instead of setting DisableFlagParsing, which would
132+
// also suppress validation for the subcommand's own required flags.
130133
for _, name := range []string{
131134
"completion",
132135
"config",
@@ -135,14 +138,13 @@ func NewRootCommand(
135138
"signup",
136139
"whoami",
137140
} {
138-
if cmd.HasParent() && cmd.Parent().Name() == name {
139-
cmd.DisableFlagParsing = true
140-
}
141-
if cmd.Name() == name {
142-
cmd.DisableFlagParsing = true
141+
if cmd.Name() == name || (cmd.HasParent() && cmd.Parent().Name() == name) {
142+
if f := cmd.Flags().Lookup(cliflags.AccessTokenFlag); f != nil {
143+
delete(f.Annotations, cobra.BashCompOneRequiredFlag)
144+
}
145+
break
143146
}
144147
}
145-
146148
},
147149
Annotations: make(map[string]string),
148150
// Handle errors differently based on type.

0 commit comments

Comments
 (0)