Skip to content

Reset flag defaults before command execution#84

Open
M09Ic wants to merge 1 commit into
reeflective:mainfrom
M09Ic:pr/console-execute-flag-defaults
Open

Reset flag defaults before command execution#84
M09Ic wants to merge 1 commit into
reeflective:mainfrom
M09Ic:pr/console-execute-flag-defaults

Conversation

@M09Ic

@M09Ic M09Ic commented Jun 27, 2026

Copy link
Copy Markdown

Background

RunCommandArgs can execute a reused cobra command tree. When the same command instance is reused, flag values and Changed state from an earlier run can leak into later executions that did not pass those flags.

Approach

  • Reset the target command's flags after availability checks and before pre-run hooks.
  • Restore scalar flag values from DefValue and clear Changed.
  • Restore slice flag values from their pflag default representation.

Tests

  • Added a regression test that runs the same command object twice.
  • The first run passes a bool flag and repeated string-slice values.
  • The second run passes no flags and verifies defaults and Changed state are restored.
  • Ran go test ./...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant