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 ./...

@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 23.99%. Comparing base (7002774) to head (9a94866).

Files with missing lines Patch % Lines
command.go 61.90% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #84      +/-   ##
==========================================
+ Coverage   22.54%   23.99%   +1.45%     
==========================================
  Files          27       27              
  Lines        2045     2067      +22     
==========================================
+ Hits          461      496      +35     
+ Misses       1554     1530      -24     
- Partials       30       41      +11     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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