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

Fixed 'extends' option to work. (#3916) #4057

Closed
wants to merge 3 commits into from
Closed

Fixed 'extends' option to work. (#3916) #4057

wants to merge 3 commits into from

Conversation

liloyek
Copy link

@liloyek liloyek commented Oct 9, 2019

Hi, I fixed this issue by applying default values at yargs(), not yargs-parser.detailed().

  • To be exact, applying 'extend' option is a feature of yargs().
  • yargs-parser just parses literally options of cli.
  • Therefore, extended configuration is overrided in yargs-parser.detailed() by default values even if there is a extends option.
  • So default values should be concatenated in yargs() so that extended configuration could be applied.

Description of the Change

Before

Default values are applied by yargs-parser.detailed in options.js.

// lib/cli/options.js

...
const result = yargsParser.detailed(args, {
    configuration,
    configObjects,
    default: defaultValues, // here
    coerce: coerceOpts,
    narg: nargOpts,
    alias: aliases,
    string: types.string,
    array: types.array,
    number: types.number,
    boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
});
...
// lib/cli/cli.js

...
yargs()
    ...
    .parserConfiguration(YARGS_PARSER_CONFIG)
    .config(args)
    .parse(args._);
};
...

After

// lib/cli/options.js

...
const result = yargsParser.detailed(args, {
  configuration,
  configObjects,
  coerce: coerceOpts,
  narg: nargOpts,
  alias: aliases,
  string: types.string,
  array: types.array,
  number: types.number,
  boolean: types.boolean.concat(nodeArgs.map(pair => pair[0]))
});
...
// lib/cli/cli.js

...
yargs()
    ...
    .parserConfiguration(YARGS_PARSER_CONFIG)
    .config(args)
    .default(mocharc) // here
    .parse(args._);
};
...

Etc

  • Added a test code at /test/integration/options/extends.spec.js.
  • Test code of 'extension' is deleted because now default values are not all applied in loadOptions() and there is a integration test for testing extension option including deleted test.

Applicable issues

fixed #3916

@jsf-clabot
Copy link

jsf-clabot commented Oct 9, 2019

CLA assistant check
All committers have signed the CLA.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 92.764% when pulling e4b90c9 on liloyek:liloyek into 3633a90 on mochajs:master.

Copy link
Member

@juergba juergba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadOptions() is a public function. You can't eliminate one important part of the option parsing which are command line - configuration files - package.json - mocha.opts - default values.

yargs-parser just parses literally options of cli.

Above statement is incorrect.

@liloyek
Copy link
Author

liloyek commented Oct 10, 2019

@juergba Thank you for review.

I chose to add default builder as above for yargs() because I thought it is the most simplest way to solve this problem.

So you mean I must not change the structure of parsing cli options and should keep the location of applying default, right?

Then is it ok to add a extra logic for processing '--extends' options in loadOptions() instead?

Thank you for your advice in advance.

@juergba
Copy link
Member

juergba commented Oct 10, 2019

I already commented this issue here. It's certainly more complex than a good-first-issue and not suited for a quick-and-dirty merge.

Then is it ok to add a extra logic for processing '--extends' options in loadOptions() instead?

Yes. I don't see any other solution at the moment.

Our configuration files are probably the ones which inherit by using --extend. Check here wether opts.config can be of any help. Which priority does it have? Before opts.configObjects or after? You really have to study and understand our parsing and its priorities. And yargs-parser and its features.

@liloyek
Copy link
Author

liloyek commented Oct 12, 2019

Ok, I should've understood more about features of yargs and yargs-parser.
I'll try to change the code as the way above.
Thank you for comments.

@outsideris outsideris added type: bug a defect, confirmed by a maintainer area: usability concerning user experience or interface labels Oct 13, 2019
@boneskull
Copy link
Member

@liloyek Do you intend to continue with this PR?

@boneskull boneskull added the stale this has been inactive for a while... label Nov 22, 2019
@liloyek
Copy link
Author

liloyek commented Nov 23, 2019

@boneskull I still want to continue, but I think it's better to close this PR and make new one after I finish it. Is it ok?

@stale stale bot removed the stale this has been inactive for a while... label Nov 23, 2019
@liloyek liloyek closed this Dec 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: usability concerning user experience or interface type: bug a defect, confirmed by a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Bug: Configurations don't seem to support 'extends'
6 participants