feat: expose ValueFormatter option through HelpOptions for custom HelpPrinters #563
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.
Motivation
When implementing custom
HelpPrinterfunctions, there was no way to access the configuredHelpValueFormatter(set viakong.ValueFormatter()). This meant custom help printers couldn't format flag and argument values consistently with the rest of Kong's help system.The
ValueFormatteris used to customise how help text is displayed for flags and positional arguments (e.g., adding environment variable suffixes, custom formatting, etc.). While this was available to Kong's built-in help printer, custom help printers had no access to it.Changes
This PR exposes the
HelpValueFormatterthrough theHelpOptionsstruct that is passed to customHelpPrinterfunctions, enabling custom help implementations to format values consistently with the application's configuration.Key changes:
ValueFormatter HelpValueFormatterfield toHelpOptionsstructContext.PrintUsage()to use a new internalContext.printHelp()method that ensures ValueFormatter is always set inHelpOptionsbefore calling the help printerhelpinvocation points to use the new patternhelpWriter.helpFormatterto usehelpWriter.HelpOptions.ValueFormatterinstead and removed the old fieldImplementation Details
The refactoring ensures that whenever a help printer is called (whether through
--help,ctx.PrintUsage(), or error handling), theValueFormatteris automatically populated from kong.helpFormatter into the HelpOptions.Backward Compatibility
This change is fully backward compatible: