Skip to content

fix: resolve hidden options with --show-hidden under strip-dashed config - #2586

Closed
hardiksh28 wants to merge 1 commit into
yargs:mainfrom
hardiksh28:fix/show-hidden-strip-dashed-2356
Closed

hardiksh28 wants to merge 1 commit into
yargs:mainfrom
hardiksh28:fix/show-hidden-strip-dashed-2356

Conversation

@hardiksh28

Copy link
Copy Markdown

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

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
@shadowspawn

Copy link
Copy Markdown
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.

@shadowspawn shadowspawn closed this Sep 5, 2026
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.

show-hidden broken if parser has strip-dashed config

2 participants