fix: resolve hidden options with --show-hidden under strip-dashed config - #2586
Closed
hardiksh28 wants to merge 1 commit into
Closed
hardiksh28 wants to merge 1 commit into
hardiksh28 wants to merge 1 commit into
Conversation
When strip-dashed parser configuration is enabled, yargs-parser converts option keys from kebab-case to camelCase in the parsed argv object. For example, --show-hidden becomes showHidden in argv. filterHiddenOptions() in lib/usage.ts was looking up argv[showHiddenOpt] where showHiddenOpt = 'show-hidden'. Under strip-dashed, this key does not exist in argv (it is stored as 'showHidden'), so the lookup always returned undefined/falsy, causing hidden options to never be revealed even when --show-hidden was explicitly passed. Fix: also check argv[shim.Parser.camelCase(showHiddenOpt)], which correctly resolves to the camelCase form that yargs-parser stores under strip-dashed. The fix handles both the default 'show-hidden' option name and any custom name passed to showHidden() that contains a dash. Fixes yargs#2356
Member
|
This is tidy, but not an urgent fix and I have other plans. My long-term goal is to add a key lookup helper function either to yargs-parser or to yargs, rather than scatter around patches for the various yargs-parser behaviours. In this case it is a default behaviour that is not covered (camel-case), and in multiple other cases it is an optional behaviour is not covered. |
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.
When strip-dashed parser configuration is enabled, yargs-parser converts option keys from kebab-case to camelCase in the parsed argv object. For example, --show-hidden becomes showHidden in argv.
filterHiddenOptions() in lib/usage.ts was looking up argv[showHiddenOpt] where showHiddenOpt = 'show-hidden'. Under strip-dashed, this key does not exist in argv (it is stored as 'showHidden'), so the lookup always returned undefined/falsy, causing hidden options to never be revealed even when --show-hidden was explicitly passed.
Fix: also check argv[shim.Parser.camelCase(showHiddenOpt)], which correctly resolves to the camelCase form that yargs-parser stores under strip-dashed.
The fix handles both the default 'show-hidden' option name and any custom name passed to showHidden() that contains a dash.
Fixes #2356