We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Reading a config file with the config option parses every letter as a separate option when yargs is used through an ES6 import.
config
For example, if this is foo.json:
foo.json
{ "foo": "bar" }
The following code:
import _yargs from 'yargs' const yargs = _yargs(process.argv); const config = yargs.config().argv; console.log(config);
Produces this result:
{ '0': '{', '1': '\n', '2': '\t', '3': '"', '4': 'f', '5': 'o', '6': 'o', '7': '"', '8': ':', '9': ' ', '10': '"', '11': 'b', '12': 'a', '13': 'r', '14': '"', '15': '\n', '16': '}', _: [ '/usr/bin/node', '/vagrant/test.js' ], config: 'foo.json', '$0': 'test.js' }
Evidently, every character from foo.json gets parsed as a separate, number-keyed option.
It works fine when using yargs through require:
require
const _yargs = require('yargs'); const yargs = _yargs(process.argv); const config = yargs.config().argv; console.log(config);
gives the expected result:
{ _: [ '/usr/bin/node', '/vagrant/test.cjs' ], config: 'foo.json', foo: 'bar', '$0': 'test.cjs' }
The text was updated successfully, but these errors were encountered:
@BadIdeaException thank you for the bug report. Would happily take a patch if anyone is interested in contributing.
Sorry, something went wrong.
At one point, there were problems with the way config files were imported (esm): issue fix
Instead of iterating through keys of a parsed object, it was iterating through indices of the unparsed json string. Does this make sense?
I'm having trouble reproducing, but I'm using the (post-fix) yargs version 17.4
index.js
yargs("cmd1 --settings ./config.json") .command( "cmd1", "cmd1 desc", (yargs) => yargs.option("opt1", { describe: "opt1 description", type: "string", required: true, }) .config("settings"), (argv) => { console.log({ argv }); } ) .parse()
config.json
{ "opt1": "The day will come when people truly understand one another" }
output
{ argv: { _: [ 'cmd1' ], settings: './config.json', opt1: 'The day will come when people truly understand one another', '$0': 'index.js' } }
@BadIdeaException is this still happening to you on the most up-to-date version of yargs?
Now working as expected. Thank you for the quick fix. 👍
jly36963
No branches or pull requests
Reading a config file with the
config
option parses every letter as a separate option when yargs is used through an ES6 import.For example, if this is
foo.json
:The following code:
Produces this result:
Evidently, every character from
foo.json
gets parsed as a separate, number-keyed option.It works fine when using yargs through
require
:gives the expected result:
The text was updated successfully, but these errors were encountered: