Skip to content

Report the flag name as typed in deprecation warnings - #500

Open
hdimer wants to merge 1 commit into
spf13:masterfrom
hdimer:fix/deprecation-typed-flag-name
Open

Report the flag name as typed in deprecation warnings#500
hdimer wants to merge 1 commit into
spf13:masterfrom
hdimer:fix/deprecation-typed-flag-name

Conversation

@hdimer

@hdimer hdimer commented Jul 30, 2026

Copy link
Copy Markdown

Fixes #279.

With an alias from SetNormalizeFunc, using the alias for a deprecated flag printed the canonical name rather than the one typed:

--dir=test  ->  Flag --src has been deprecated, ...   # before
--dir=test  ->  Flag --dir has been deprecated, ...   # after

Parse's callback passed flag.Name into Set, so the typed name was gone before the warning was built. This threads the typed name through the internal parseFunc so the warning reports it. Long flags report the typed alias; shorthands keep the canonical long name (no alias to report). Public Set/ParseAll signatures are unchanged; calling Set directly with an alias now echoes that alias.

Added TestDeprecatedFlagUsageAlias.

Used AI assistance on this; I reviewed and tested it.

When a NormalizeFunc aliases a flag name, using the alias for a
deprecated flag printed the canonical name rather than the one the
user typed. Parse passed the normalized flag.Name into Set, so the
typed name was lost before the warning was built.

Thread the typed name through the internal parseFunc so the warning
reports it. Long flags report the typed alias; shorthands keep the
canonical long name. Public Set/ParseAll signatures are unchanged.

Fixes spf13#279
@CLAassistant

CLAassistant commented Jul 30, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.

MarkDeprecated and NormalizeFunc as alias results in an inconsistent deprecation message

2 participants