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

Inconsistent array parsing(string values are wrapped in an array instead of parsed) #82

Closed
le0nik opened this issue Feb 21, 2017 · 3 comments
Assignees

Comments

@le0nik
Copy link

le0nik commented Feb 21, 2017

Original issue: yargs/yargs#789.

The string values are parsed correctly in case of boolean or number values, but are not in case of array. Something like https://github.com/mccormicka/string-argv could be used to parse strings into arrays(simple parsing might not work because quotes must be considered, too).

Passed through cli:

const argv = require('yargs')
  .options({
    arr: {
      type: 'array',
    },
  })
  .argv;

console.log('argv', argv);

$ node ./test.js --arr foo bar
Outputs: argv { _: [], arr: [ 'foo', 'bar' ], '$0': 'test.js' }

Passed through .config()

const argv = require('yargs')
  .config({
    arr: 'foo bar',
  })
  .options({
    arr: {
      type: 'array',
    },
  })
  .argv;

console.log('argv', argv);

$ node ./test.js
Outputs: argv { _: [], arr: [ 'foo bar' ], '$0': 'test.js' }

yargs@6.6.0

@bcoe bcoe added the bug label Mar 22, 2017
@bcoe
Copy link
Member

bcoe commented Mar 22, 2017

@le0nik thanks for opening this issue; we're playing catch up right now, but will work on getting to this ASAP!

@JaKXz
Copy link
Member

JaKXz commented Apr 15, 2017

Good news! I have a failing test around this (I think). PR coming soon!

@bcoe
Copy link
Member

bcoe commented Jan 1, 2018

@le0nik @JaKXz having revisited this, my feeling is that this behavior is actually reasonable -- although we may want to document it somewhere?

My expectation with .config is that that the object passed would already have split arrays and objects out, so something like this:

.config({
  foo: ["a", "b"],
  bar: {
     a: 99,
     b: 33
   }
})

This makes it easy to load a JSON configuration file of disk and use it to populate yargs. tldr; I don't think we should think of the values passed to .config as unparsed command line values, rather they're an intermediate JSON representation.

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

No branches or pull requests

3 participants