Skip to content

Conversation

@ldemailly
Copy link
Member

No description provided.

@ldemailly ldemailly requested a review from Copilot September 11, 2025 21:14
@codecov
Copy link

codecov bot commented Sep 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (ab24874) to head (1f1166e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main        #3   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines          182       181    -1     
=========================================
- Hits           182       181    -1     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug in the default value handling for duration flags and adds comprehensive test coverage. The fix ensures that duration flags properly display their default values in help text using the human-readable format (e.g., "1d3h") instead of the standard time.Duration format.

  • Fixed initialization order issue in FlagSetVar function to prevent incorrect default value display
  • Added test to verify default values are properly shown in help text
  • Added test to ensure zero default values don't show "(default" text in help

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
duration.go Fixed bug in FlagSetVar by reordering variable assignment and flag registration
duration_test.go Added imports and two test functions to verify help text behavior with default values

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// FlagSet is like [FlagVar] but for the specified flag set. Replacement for [flag.FlagSet.DurationVar].
func FlagSetVar(fs *flag.FlagSet, p *time.Duration, name string, value time.Duration, usage string) {
d := Duration(value)
*p = value
Copy link

Copilot AI Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix creates a potential issue where *p is set to the raw time.Duration value before registering the flag. This means the flag's String() method will return the standard Go duration format (e.g., '27h0m0s') instead of the human-readable format (e.g., '1d3h') for default values in help text. Consider creating a Duration instance first to ensure proper formatting: d := Duration(value); *p = time.Duration(d); fs.Var((*Duration)(p), name, usage)

Suggested change
*p = value
d := Duration(value)
*p = time.Duration(d)

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix actually - need value indeed to be set for default to work

@ldemailly ldemailly merged commit b92a782 into main Sep 11, 2025
8 checks passed
@ldemailly ldemailly deleted the default_in_help branch September 11, 2025 21:33
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