Skip to content

Commit 74734c3

Browse files
authored
Fix do and root flags (#23355)
Fix the top level pulumi command to do it's own flag parse when running against commands like `do` which disable cobras default argument parsing.
1 parent 8deae80 commit 74734c3

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
component: cli/do
2+
kind: fix
3+
body: Fix top level flags like `--logtostderr` being recognized when using `pulumi do`
4+
time: 2026-05-27T17:59:48.969894+01:00
5+
custom:
6+
PR: "23355"

‎pkg/cmd/pulumi/pulumi.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,18 @@ func NewPulumiCmd() (*cobra.Command, func()) {
275275
}
276276
}()
277277

278+
// Commands like `pulumi do` set DisableFlagParsing on themselves so they can
279+
// build a dynamic flag tree from a provider's schema. cobra skips flag parsing
280+
// entirely for such commands, which means our root persistent flag variables
281+
// (--color, --cwd, --tracing, --otel-traces, ...) are still at their defaults
282+
// when this PersistentPreRunE runs, so all the flag-dependent init below is
283+
// skipped. Parse what we can ourselves before continuing.
284+
if cmd.DisableFlagParsing {
285+
pf := cmd.Root().PersistentFlags()
286+
pf.ParseErrorsAllowlist.UnknownFlags = true
287+
_ = pf.Parse(args)
288+
}
289+
278290
commandPath := strings.TrimSpace(strings.TrimPrefix(cmd.CommandPath(), "pulumi"))
279291
client.SetUserAgentCommand(commandPath)
280292
client.SetUserAgentAIAgent(agentdetect.Detect(os.Getenv))

0 commit comments

Comments
 (0)