yargs-parser
Advanced tools
Comparing version 1.1.1-alpha3 to 2.0.0
24
index.js
@@ -0,4 +1,3 @@ | ||
var assign = require('lodash.assign') | ||
var camelCase = require('camelcase') | ||
var pkgConf = require('pkg-conf') | ||
var requireMainFilename = require('require-main-filename') | ||
var path = require('path') | ||
@@ -15,3 +14,9 @@ var tokenizeArgString = require('./lib/tokenize-arg-string') | ||
var aliases = combineAliases(opts.alias || {}) | ||
var configuration = loadConfiguration(opts.cwd || requireMainFilename()) | ||
var configuration = assign({}, { | ||
'short-option-groups': true, | ||
'camel-case-expansion': true, | ||
'dot-notation': true, | ||
'parse-numbers': true, | ||
'boolean-negation': true | ||
}, opts.configuration) | ||
var defaults = opts.default || {} | ||
@@ -558,15 +563,2 @@ var envPrefix = opts.envPrefix | ||
function loadConfiguration (cwd) { | ||
return pkgConf.sync('yargs', { | ||
defaults: { | ||
'short-option-groups': true, | ||
'camel-case-expansion': true, | ||
'dot-notation': true, | ||
'parse-numbers': true, | ||
'boolean-negation': true | ||
}, | ||
cwd: cwd | ||
}) | ||
} | ||
// if any aliases reference each other, we should | ||
@@ -573,0 +565,0 @@ // merge them together. |
{ | ||
"name": "yargs-parser", | ||
"version": "1.1.1-alpha3", | ||
"version": "2.0.0", | ||
"description": "the mighty option parser used by yargs", | ||
@@ -28,14 +28,12 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "^3.4.1", | ||
"chai": "^3.5.0", | ||
"coveralls": "^2.11.6", | ||
"mocha": "^2.3.4", | ||
"nyc": "^5.3.0", | ||
"rimraf": "^2.5.1", | ||
"mocha": "^2.4.5", | ||
"nyc": "^5.6.0", | ||
"standard": "^5.4.1" | ||
}, | ||
"dependencies": { | ||
"camelcase": "^2.0.1", | ||
"pkg-conf": "^1.1.1", | ||
"require-main-filename": "^1.0.0" | ||
"camelcase": "^2.1.0", | ||
"lodash.assign": "^4.0.2" | ||
} | ||
} |
@@ -61,2 +61,3 @@ # yargs-parser | ||
* `opts.string`: keys should be treated as strings (even if they resemble a number `-x 33`). | ||
* `opts.configuration`: provide configuration options to the yargs-parser (see: [configuration](#configuration)). | ||
@@ -89,15 +90,15 @@ **returns:** | ||
<a name="configuration"></a> | ||
### Configuration | ||
The yargs-parser applies several automated transformations on the keys provided | ||
in `args`. These features can be turned on and off by using the `yargs` | ||
configuration stanza in your package.json: | ||
in `args`. These features can be turned on and off using the `configuration` field | ||
of `opts`. | ||
```json | ||
{ | ||
"name": "my-awesome-module", | ||
"yargs": { | ||
"dot-notation": false | ||
```js | ||
var parsed = parser(['--no-dice'], { | ||
configuration: { | ||
'boolean-negation': false | ||
} | ||
} | ||
}) | ||
``` | ||
@@ -104,0 +105,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* global beforeEach, describe, it, afterEach */ | ||
/* global beforeEach, describe, it */ | ||
@@ -9,3 +9,2 @@ require('chai').should() | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
@@ -1416,37 +1415,14 @@ describe('yargs-parser', function () { | ||
describe('configuration', function () { | ||
beforeEach(function () { | ||
rimraf.sync('./test/fixtures/package.json') | ||
}) | ||
afterEach(function () { | ||
rimraf.sync('./test/fixtures/package.json') | ||
}) | ||
it('reads configuration from parent package.json', function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
'short-option-groups': false | ||
} | ||
}), 'utf-8') | ||
var result = parser.detailed([], { | ||
cwd: './test/fixtures/inner' | ||
}) | ||
result.configuration['short-option-groups'].should.equal(false) | ||
}) | ||
describe('short option groups', function () { | ||
it('allows short-option-groups to be disabled', function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
var parse = parser(['-cats=meow'], { | ||
configuration: { | ||
'short-option-groups': false | ||
} | ||
}), 'utf-8') | ||
var parse = parser(['-cats=meow'], { | ||
cwd: './test/fixtures/inner' | ||
}) | ||
parse.cats.should.equal('meow') | ||
parse = parser(['-cats', 'meow'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'short-option-groups': false | ||
} | ||
}) | ||
@@ -1458,10 +1434,2 @@ parse.cats.should.equal('meow') | ||
describe('camel-case expansion', function () { | ||
beforeEach(function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
'camel-case-expansion': false | ||
} | ||
}), 'utf-8') | ||
}) | ||
it('does not expand camel-case aliases', function () { | ||
@@ -1472,3 +1440,5 @@ var parsed = parser.detailed([], { | ||
}, | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'camel-case-expansion': false | ||
} | ||
}) | ||
@@ -1482,3 +1452,5 @@ | ||
var parsed = parser.detailed(['--foo-bar=apple'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'camel-case-expansion': false | ||
} | ||
}) | ||
@@ -1492,10 +1464,2 @@ | ||
describe('dot notation', function () { | ||
beforeEach(function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
'dot-notation': false | ||
} | ||
}), 'utf-8') | ||
}) | ||
it('does not expand dot notation defaults', function () { | ||
@@ -1506,3 +1470,5 @@ var parsed = parser([], { | ||
}, | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'dot-notation': false | ||
} | ||
}) | ||
@@ -1515,7 +1481,11 @@ | ||
var parsed = parser(['--foo.bar', 'banana'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'dot-notation': false | ||
} | ||
}) | ||
expect(parsed['foo.bar']).to.equal('banana') | ||
parsed = parser(['--foo.bar=banana'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'dot-notation': false | ||
} | ||
}) | ||
@@ -1527,10 +1497,2 @@ expect(parsed['foo.bar']).to.equal('banana') | ||
describe('parse numbers', function () { | ||
beforeEach(function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
'parse-numbers': false | ||
} | ||
}), 'utf-8') | ||
}) | ||
it('does not coerce defaults into numbers', function () { | ||
@@ -1541,3 +1503,5 @@ var parsed = parser([], { | ||
}, | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'parse-numbers': false | ||
} | ||
}) | ||
@@ -1550,3 +1514,5 @@ | ||
var parsed = parser(['--foo', '5'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'parse-numbers': false | ||
} | ||
}) | ||
@@ -1558,3 +1524,5 @@ expect(parsed['foo']).to.equal('5') | ||
var parsed = parser(['5'], { | ||
cwd: './test/fixtures/inner' | ||
configuration: { | ||
'parse-numbers': false | ||
} | ||
}) | ||
@@ -1566,13 +1534,7 @@ expect(parsed._[0]).to.equal('5') | ||
describe('boolean negation', function () { | ||
beforeEach(function () { | ||
fs.writeFileSync('./test/fixtures/package.json', JSON.stringify({ | ||
yargs: { | ||
it('does not negate arguments prefixed with --no-', function () { | ||
var parsed = parser(['--no-dice'], { | ||
configuration: { | ||
'boolean-negation': false | ||
} | ||
}), 'utf-8') | ||
}) | ||
it('does not negate arguments prefixed with --no-', function () { | ||
var parsed = parser(['--no-dice'], { | ||
cwd: './test/fixtures/inner' | ||
}) | ||
@@ -1579,0 +1541,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
2
5
1
207
73989
14
1929
+ Addedlodash.assign@^4.0.2
+ Addedlodash.assign@4.2.0(transitive)
- Removedpkg-conf@^1.1.1
- Removedrequire-main-filename@^1.0.0
- Removederror-ex@1.3.2(transitive)
- Removedfind-up@1.1.2(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedis-arrayish@0.2.1(transitive)
- Removedis-utf8@0.2.1(transitive)
- Removedload-json-file@1.1.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedparse-json@2.2.0(transitive)
- Removedpath-exists@2.1.0(transitive)
- Removedpify@2.3.0(transitive)
- Removedpinkie@2.0.4(transitive)
- Removedpinkie-promise@2.0.1(transitive)
- Removedpkg-conf@1.1.3(transitive)
- Removedrequire-main-filename@1.0.1(transitive)
- Removedstrip-bom@2.0.0(transitive)
- Removedsymbol@0.2.3(transitive)
Updatedcamelcase@^2.1.0