Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show-hidden broken if parser has strip-dashed config #2356

Open
YarnSaw opened this issue Sep 6, 2023 · 2 comments
Open

show-hidden broken if parser has strip-dashed config #2356

YarnSaw opened this issue Sep 6, 2023 · 2 comments
Labels

Comments

@YarnSaw
Copy link

YarnSaw commented Sep 6, 2023

Minimal Repro:

const yargs = require('yargs')

yargs
  .help('help', 'help')
  .showHidden('show-hidden', 'Show hidden options')
  .options({
    foo: {
      describe: 'bar',
      type: 'string',
      hidden: true,
    }})
  .parserConfiguration({
    'strip-dashed': true,
  })
  .argv;

Outputs:

$ node test.js --help --show-hidden
Options:
  --version      Show version number                                   [boolean]
  --help         help                                                  [boolean]
  --show-hidden  Show hidden options                                   [boolean]

Where the foo option isn't shown, despite --help and --show-hidden being specified. If 'strip-dashed': true, is commented out, the new output is:

$ node test.js --help --show-hidden
Options:
  --version      Show version number                                   [boolean]
  --help         help                                                  [boolean]
  --show-hidden  Show hidden options                                   [boolean]
  --foo          bar                                                    [string]

Which is properly displaying the foo option.

@shadowspawn shadowspawn added the bug label Sep 7, 2023
@shadowspawn
Copy link
Member

Thanks for report. I reproduced, and think it is a bug.

A work-around would be to use an option name without a dash with showHidden. (Which you likely realised, having helpfully tracked down the dependence on 'strip-dashed'.)

This is one of several bugs introduced by allowing the author to call parserConfiguration. Sigh. Flexibility leads to complications! Yargs needs to do more work to find whether a "known" option is present in the parsed args. The (overly) simple check is:

(yargs.parsed as DetailedArguments).argv[yargs.getOptions().showHiddenOpt]

One of the previous fixes for a situation where Yargs wanted to iterate over all the possible permutations was:
#2308

This case is simpler, just want to lookup option by any name. That could be done by taking into account the parserConfiguration, or could be done by iterating over the aliases. Given this has come up a few times I would like to add a utility routine to wrap the logic.

@YarnSaw
Copy link
Author

YarnSaw commented Sep 7, 2023

My current solution was to remove the strip-dashed since I didn't like the aesthetic of showHidden being camel case with the rest of the options being kebab case 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants