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

Key names of an object setting are parsed as dot-notation #716

Closed
strugee opened this issue Nov 25, 2016 · 6 comments · Fixed by #722
Closed

Key names of an object setting are parsed as dot-notation #716

strugee opened this issue Nov 25, 2016 · 6 comments · Fixed by #722
Labels

Comments

@strugee
Copy link

strugee commented Nov 25, 2016

Given the following (abbreviated) yargs config:

var argv = require('yargs')
	   .describe({port: 'Port that the HTTP server will bind to',
	              address: 'Address that the HTTP server will bind to',
	              path: 'Path that the server will clone things to',
	              override: 'Key/value pairs to override directory names'})
	   .default({ config: '/etc/gh-pages-server.json', address: '0.0.0.0', port: 8000, path: '/srv/http', override: {} })
	   .config()
	   .argv;

And the following /etc/gh-pages-server.json:

{
  "override": {
    "strugee/strugee.github.com": "default"
  }
}

yargs produces an argv object that contains:

"override": {
  "strugee/strugee": { "github": { "com": "default"} }
}

whereas the intended result was something like:

"override": {
  "strugee/strugee.github.com": "default"
}

I tried setting dot-notation to false in my package.json, but that generated a config key that looked like:

"override.strugee/strugee.github.com": "default",
"override": {}

which obviously also isn't what was intended.

@bcoe bcoe added the bug label Nov 26, 2016
@bcoe
Copy link
Member

bcoe commented Nov 26, 2016

@strugee thanks for reporting this bug, I will work on putting some tests around this behavior.

@bcoe
Copy link
Member

bcoe commented Nov 28, 2016

@strugee does this fix seem reasonable? yargs/yargs-parser#72

@strugee
Copy link
Author

strugee commented Nov 28, 2016

@bcoe I'm not familiar with yargs-parser so I'm not quite in a position to judge, but it seems pretty good! Thanks!

@bcoe
Copy link
Member

bcoe commented Dec 1, 2016

@strugee this should now be fixed in yargs@6.5.0 take it for a spin and let me know if you run into any issues.

@geekdada
Copy link

I put package.json in config, and it still messes up.

  expect: { js: '^0.3.1' },
  'json-schema-faker': '^0.4.0',
  mocha: '^2.5.3',
  'npm-check': '^5.4.0',
  once: '^1.3.2',
  pedding: '^1.0.0',
  promise: { prototype: { finally: '^2.0.1' } },

@maxrimue maxrimue reopened this Jan 2, 2017
@bcoe
Copy link
Member

bcoe commented Jan 2, 2017

@geekdada @maxrimue I believe this issue is that you haven't turned off dot-notation in your yargs configuration; I just confirmed that this worked on 6.6.0:

yargs config in package.json:

  "yargs": {
    "dot-notation": false
  }

config.json:

{
  "expect.js": "3.2.9",
  "promise.prototype.finally": "3.3.3"
}

yargs output:

{ _: [],
  foo: 'b.json',
  'expect.js': '3.2.9',
  'promise.prototype.finally': '3.3.3',
  '$0': 'index.js',
  x: undefined }

@bcoe bcoe closed this as completed Jan 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants