Add Context.showEnvvarsInHelp to show envvar names in help output#641
Open
gildor wants to merge 1 commit into
Open
Add Context.showEnvvarsInHelp to show envvar names in help output#641gildor wants to merge 1 commit into
gildor wants to merge 1 commit into
Conversation
Add an opt-in context setting that shows the name of the environment variable an option reads its value from in the help output, rendered through the existing help tag pipeline as "(env var: FOO)". Both explicit envvar names and names inferred from autoEnvvarPrefix are shown. Since the setting is on the context, it propagates to subcommands. Individual options can override the displayed name (or hide it) by setting the new HelpFormatter.Tags.ENVVAR key in their helpTags. The tag text is localizable via Localization.helpTagEnvvar, and rendering is customizable through the existing renderTag/shouldShowTag/ styleHelpTag formatter hooks, same as the default and required tags. References ajalt#320
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.
Adds an opt-in way to show the name of the environment variable that an option reads its value from in the
--helpoutput:Both explicit
envvarnames and names inferred fromautoEnvvarPrefixare shown. Eager options (like--helpand--version) never read envvars, so they never get the tag.The tag is computed in
Option.parameterHelp(context)- the only place with access to both the option'senvvarand the context'sautoEnvvarPrefix— and flows through the existing help tag pipeline, so no formatter changes were needed beyond localizing the newHelpFormatter.Tags.ENVVARtag. It renders identically inMordantHelpFormatter,PlaintextHelpFormatter, and the markdown formatter.That also means all the existing customization hooks apply to it for free:
Localization.helpTagEnvvar()(defaults to"env var")renderTag/shouldShowTagformatter methodsstyleHelpTag(theme.style("muted")), same as the other tagsPer-option override
Individual options can override the global setting through their existing
helpTagsparameter:Default
The setting is off by default, so existing help output is byte-identical. Since envvar support is invisible to users without this (see request in #320), probably it is worth enabling it by default in a future release - happy to follow whatever you prefer here.
Closes #320