Repository navigation
fix: use FlagNamePrefixer and FlagEnvHinter in the default flag stringer - #2494
Merged
Merged
Conversation
Juneezee
force-pushed
the
fix/flag-hint-hooks
branch
from
October 24, 2026 15:53
4646dad to
86c0618
Compare
Both are documented as "used by the default FlagStringer", but stringifyFlag called prefixedNames and withEnvHint directly, so setting them had no effect. Their defaults are those same functions, so the default help output doesn't change. FlagFileHinter and FlagFileHintFunc had the same claim, but nothing has called FlagFileHinter since v2, so their comments now say the default FlagStringer doesn't use it. TestFlagEnvHinter, commented out since the v2 merge, is restored for v3, with a TestFlagNamePrefixer next to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
Juneezee
force-pushed
the
fix/flag-hint-hooks
branch
from
October 24, 2026 16:13
86c0618 to
b134c57
Compare
Juneezee
approved these changes
Oct 24, 2026
Juneezee
left a comment
Member
There was a problem hiding this comment.
Thanks! Confirmed on main: setting FlagEnvHinter or FlagNamePrefixer doesn't change the help output, and with this PR it does. Both new tests fail on main and pass here.
I pushed a few changes:
- Rebased onto main.
- Removed the table from the old
TestFlagNamePrefixer, which was still a deadvar _. Your newTestFlagNamePrefixerreplaces it. - Reworded the
FlagFileHinterandFlagFileHintFunccomments to say the defaultFlagStringerdoesn't use them. Showing file sources would change the help of every flag with aFilesource, so I kept this to the comments. I also updated the description to match.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
What this PR does / why we need it:
FlagNamePrefixerandFlagEnvHinterare exported variables documented as "used by the default FlagStringer", butstringifyFlagcallsprefixedNamesandwithEnvHintdirectly, so setting them changes nothing:stringifyFlagnow calls the two variables. Their defaults areprefixedNamesandwithEnvHint, so help output only changes for programs that set them. This includes the per-flagStringeroverride path, since that falls back toFlagStringer.FlagFileHinterhas the same comment, but help doesn't show file sources at all today (FlagFileHinterandwithFileHinthaven't been called since v2), so using it would add text to the help of every flag with aFilesource. Instead, its comment andFlagFileHintFunc's now say the defaultFlagStringerdoesn't use it (the old comment also said "environment variable details").Which issue(s) this PR fixes:
None, found while reading the help code.
Testing
TestFlagEnvHinterhad been commented out since the v2 merge (its table was later renamed tovar _to silence the linter). It's restored for v3 (Sources, thestringplaceholder), with a newTestFlagNamePrefixernext to it. Both fail onmain.make(generate, vet, tests, binary size, gfmrun),make lintandmake v3diffpass.go test -racepasses, as do the tests withurfave_cli_no_template,urfave_cli_no_docsandurfave_cli_no_suggest.The change and the tests were written with Claude Code (AI).
Release Notes
🤖 Generated with Claude Code