yargs
Advanced tools
Comparing version 1.3.1 to 1.3.2
11
index.js
@@ -354,5 +354,8 @@ var path = require('path'); | ||
var aliasKeys = (Object.keys(options.alias) || []) | ||
.concat(Object.keys(self.parsed.newAliases) || []); | ||
keys = keys.filter(function(key) { | ||
return Object.keys(options.alias).every(function(alias) { | ||
return -1 == options.alias[alias].indexOf(key); | ||
return !self.parsed.newAliases[key] && aliasKeys.every(function(alias) { | ||
return -1 == (options.alias[alias] || []).indexOf(key); | ||
}); | ||
@@ -455,2 +458,4 @@ }); | ||
self.parsed = parsed; | ||
Object.keys(argv).forEach(function(key) { | ||
@@ -462,3 +467,3 @@ if (key === helpOpt) { | ||
else if (key === versionOpt) { | ||
console.log(version); | ||
process.stdout.write(version); | ||
process.exit(0); | ||
@@ -465,0 +470,0 @@ } |
@@ -35,3 +35,5 @@ var path = require('path'); | ||
var aliases = {}; | ||
var aliases = {}, | ||
newAliases = {}; | ||
Object.keys(opts.alias || {}).forEach(function (key) { | ||
@@ -42,3 +44,5 @@ aliases[key] = [].concat(opts.alias[key]); | ||
if (/-/.test(x)) { | ||
aliases[key].push(toCamelCase(x)); | ||
var c = toCamelCase(x); | ||
aliases[key].push(c); | ||
newAliases[c] = true; | ||
} | ||
@@ -57,3 +61,5 @@ }); | ||
if (/-/.test(key) && !opts.alias[key]) { | ||
aliases[key] = (aliases[key] || []).concat(toCamelCase(key)); | ||
var c = toCamelCase(key); | ||
aliases[key] = (aliases[key] || []).concat(c); | ||
newAliases[c] = true; | ||
} | ||
@@ -79,3 +85,5 @@ (aliases[key] || []).forEach(function (alias) { | ||
if (/-/.test(key) && !(aliases[key] && aliases[key].length)) { | ||
aliases[key] = [toCamelCase(key)]; | ||
var c = toCamelCase(key); | ||
aliases[key] = [c]; | ||
newAliases[c] = true; | ||
} | ||
@@ -235,3 +243,4 @@ | ||
argv: argv, | ||
aliases: aliases | ||
aliases: aliases, | ||
newAliases: newAliases | ||
}; | ||
@@ -238,0 +247,0 @@ }; |
{ | ||
"name": "yargs", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -33,2 +33,18 @@ "main": "./index.js", | ||
}, | ||
"contributors": [ | ||
{ | ||
"name": "Chris Needham", | ||
"email": "chris@chrisneedham.com", | ||
"url": "http://chrisneedham.com" | ||
}, | ||
{ | ||
"name": "James Nylen", | ||
"email": "jnylen@gmail.com", | ||
"url": "https://github.com/nylen" | ||
}, | ||
{ | ||
"name": "Benjamin Horsleben", | ||
"url": "https://github.com/fizker" | ||
} | ||
], | ||
"license": "MIT/X11", | ||
@@ -35,0 +51,0 @@ "engine": { |
yargs | ||
======== | ||
Yargs be a node.js library fer hearties tryin' ter parse optstrings against their will where even the boo box be not enough to coerce them. This here module is fer scallywags lookin' ter plunder all the sunken -shipz of their --treasures thru program usage but be tired of optstrings disincling to acquiesce to yer requests. | ||
Yargs be a node.js library fer hearties tryin' ter parse optstrings. | ||
@@ -19,3 +19,3 @@ With yargs, ye be havin' a map that leads straight to yer treasure! Treasure of course, being a simple option hash. | ||
With yargs, the options be just a hash! No optstrings be attached. | ||
With yargs, the options be just a hash! | ||
------------------------------------------------------------------- | ||
@@ -47,3 +47,3 @@ | ||
But don' walk the plank jus' yet! Ther' be more! Ye can do short options: | ||
But don't walk the plank just yet! There be more! You can do short options: | ||
------------------------------------------------- | ||
@@ -64,3 +64,3 @@ | ||
And gold doubooleans, both long an' short (an' grouped!): | ||
And booleans, both long, short, and even grouped: | ||
---------------------------------- | ||
@@ -116,3 +116,3 @@ | ||
Yargs even counts yer gold doubooleans! | ||
Yargs even counts your booleans! | ||
---------------------------------------------------------------------- | ||
@@ -158,3 +158,3 @@ | ||
Tell yer friends how ter use yer options and make demands from yer enemies. | ||
Tell users how to use yer options and make demands. | ||
------------------------------------------------- | ||
@@ -246,3 +246,3 @@ | ||
And if ye really want ter get all descriptive about it... | ||
And if you really want to get all descriptive about it... | ||
--------------------------------------------------------- | ||
@@ -287,3 +287,3 @@ | ||
Yargs is here ter help ye... | ||
Yargs is here to help you... | ||
--------------------------- | ||
@@ -290,0 +290,0 @@ |
@@ -656,2 +656,25 @@ var should = require('chai').should(), | ||
}); | ||
it('should not show both dashed and camelCase aliases', function () { | ||
var r = checkUsage(function () { | ||
return yargs(['--help']) | ||
.usage('Usage: $0 options') | ||
.help('help') | ||
.describe('some-opt', 'Some option') | ||
.default('some-opt', 2) | ||
.argv; | ||
}); | ||
r.should.have.property('result'); | ||
r.result.should.have.property('_').with.length(0); | ||
r.should.have.property('exit').and.be.ok; | ||
r.should.have.property('errors').with.length(0); | ||
r.should.have.property('logs'); | ||
r.logs.join('\n').split(/\n+/).should.deep.equal([ | ||
'Usage: ./usage options', | ||
'Options:', | ||
' --help Show help ', | ||
' --some-opt Some option [default: 2]', | ||
'' | ||
]); | ||
}); | ||
}); | ||
@@ -718,2 +741,3 @@ | ||
process._argv = process.argv; | ||
process.stdout._write = process.stdout.write; | ||
@@ -723,2 +747,3 @@ process.exit = function () { exit = true }; | ||
process.argv = [ './usage' ]; | ||
process.stdout.write = function (msg) { logs.push(msg) }; | ||
@@ -738,2 +763,3 @@ var errors = []; | ||
process.argv = process._argv; | ||
process.stdout.write = process.stdout._write; | ||
@@ -740,0 +766,0 @@ console.error = console._error; |
113950
2420