Comparing version 3.29.0 to 3.30.0
## Change Log | ||
### v3.30.0 (2015/11/13 16:29 +07:00) | ||
- [#293](https://github.com/bcoe/yargs/pull/293) Polish language support (@kamilogorek). | ||
- [#291](https://github.com/bcoe/yargs/pull/291) fix edge-cases with `.alias()` (@bcoe) | ||
- [#289](https://github.com/bcoe/yargs/pull/289) group options in custom groups (@bcoe) | ||
### v3.29.0 (2015/10/16 21:51 +07:00) | ||
@@ -4,0 +10,0 @@ |
31
index.js
@@ -169,3 +169,21 @@ var assert = require('assert') | ||
} else { | ||
options.alias[x] = (options.alias[x] || []).concat(y) | ||
// perhaps 'x' is already an alias in another list? | ||
// if so we should append to x's list. | ||
var aliases = null | ||
Object.keys(options.alias).forEach(function (key) { | ||
if (~options.alias[key].indexOf(x)) aliases = options.alias[key] | ||
}) | ||
if (aliases) { // x was an alias itself. | ||
aliases.push(y) | ||
} else { // x is a new alias key. | ||
options.alias[x] = (options.alias[x] || []).concat(y) | ||
} | ||
// wait! perhaps we've created two lists of aliases | ||
// that reference each other? | ||
if (options.alias[y]) { | ||
Array.prototype.push.apply((options.alias[x] || aliases), options.alias[y]) | ||
delete options.alias[y] | ||
} | ||
} | ||
@@ -286,2 +304,4 @@ return self | ||
self.choices(key, opt.choices) | ||
} if ('group' in opt) { | ||
self.group(key, opt.group) | ||
} if (opt.boolean || opt.type === 'boolean') { | ||
@@ -318,2 +338,11 @@ self.boolean(key) | ||
var groups = {} | ||
self.group = function (opts, groupName) { | ||
groups[groupName] = (groups[groupName] || []).concat(opts) | ||
return self | ||
} | ||
self.getGroups = function () { | ||
return groups | ||
} | ||
self.wrap = function (cols) { | ||
@@ -320,0 +349,0 @@ usage.wrap(cols) |
@@ -104,2 +104,3 @@ // this file handles outputting usage instructions, | ||
var defaultGroup = 'Options:' | ||
self.help = function () { | ||
@@ -109,2 +110,3 @@ normalizeAliases() | ||
var demanded = yargs.getDemanded() | ||
var groups = yargs.getGroups() | ||
var options = yargs.getOptions() | ||
@@ -146,3 +148,4 @@ var keys = Object.keys( | ||
// the options table. | ||
// perform some cleanup on the keys array, making it | ||
// only include top-level keys not their aliases. | ||
var aliasKeys = (Object.keys(options.alias) || []) | ||
@@ -157,16 +160,35 @@ .concat(Object.keys(yargs.parsed.newAliases) || []) | ||
var switches = keys.reduce(function (acc, key) { | ||
acc[key] = [ key ].concat(options.alias[key] || []) | ||
.map(function (sw) { | ||
return (sw.length > 1 ? '--' : '-') + sw | ||
// populate 'Options:' group with any keys that have not | ||
// explicitly had a group set. | ||
if (!groups[defaultGroup]) groups[defaultGroup] = [] | ||
addUngroupedKeys(keys, options.alias, groups) | ||
// display 'Options:' table along with any custom tables: | ||
Object.keys(groups).forEach(function (groupName) { | ||
if (!groups[groupName].length) return | ||
ui.div(__(groupName)) | ||
// if we've grouped the key 'f', but 'f' aliases 'foobar', | ||
// normalizedKeys should contain only 'foobar'. | ||
var normalizedKeys = groups[groupName].map(function (key) { | ||
if (~aliasKeys.indexOf(key)) return key | ||
for (var i = 0, aliasKey; (aliasKey = aliasKeys[i]) !== undefined; i++) { | ||
if (~(options.alias[aliasKey] || []).indexOf(key)) return aliasKey | ||
} | ||
return key | ||
}) | ||
.join(', ') | ||
return acc | ||
}, {}) | ||
// actually generate the switches string --foo, -f, --bar. | ||
var switches = normalizedKeys.reduce(function (acc, key) { | ||
acc[key] = [ key ].concat(options.alias[key] || []) | ||
.map(function (sw) { | ||
return (sw.length > 1 ? '--' : '-') + sw | ||
}) | ||
.join(', ') | ||
if (keys.length) { | ||
ui.div(__('Options:')) | ||
return acc | ||
}, {}) | ||
keys.forEach(function (key) { | ||
normalizedKeys.forEach(function (key) { | ||
var kswitch = switches[key] | ||
@@ -202,3 +224,3 @@ var desc = descriptions[key] || '' | ||
ui.div() | ||
} | ||
}) | ||
@@ -268,3 +290,2 @@ // describe some common use-cases for your application. | ||
if (demanded[alias]) yargs.demand(key, demanded[alias].msg) | ||
// type messages. | ||
@@ -280,2 +301,22 @@ if (~options.boolean.indexOf(alias)) yargs.boolean(key) | ||
// given a set of keys, place any keys that are | ||
// ungrouped under the 'Options:' grouping. | ||
function addUngroupedKeys (keys, aliases, groups) { | ||
var groupedKeys = [] | ||
var toCheck = null | ||
Object.keys(groups).forEach(function (group) { | ||
groupedKeys = groupedKeys.concat(groups[group]) | ||
}) | ||
keys.forEach(function (key) { | ||
toCheck = [key].concat(aliases[key]) | ||
if (!toCheck.some(function (k) { | ||
return groupedKeys.indexOf(k) !== -1 | ||
})) { | ||
groups[defaultGroup].push(key) | ||
} | ||
}) | ||
return groupedKeys | ||
} | ||
self.showHelp = function (level) { | ||
@@ -282,0 +323,0 @@ level = level || 'error' |
{ | ||
"name": "yargs", | ||
"version": "3.29.0", | ||
"version": "3.30.0", | ||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -16,3 +16,3 @@ "main": "./index.js", | ||
"cliui": "^3.0.3", | ||
"decamelize": "^1.0.0", | ||
"decamelize": "^1.1.1", | ||
"os-locale": "^1.4.0", | ||
@@ -23,3 +23,3 @@ "window-size": "^0.1.2", | ||
"devDependencies": { | ||
"chai": "^3.3.0", | ||
"chai": "^3.4.1", | ||
"chalk": "^1.1.1", | ||
@@ -26,0 +26,0 @@ "coveralls": "^2.11.4", |
@@ -652,2 +652,23 @@ yargs | ||
<a name="group"></a>.group(key(s), groupName) | ||
-------------------- | ||
Given a key, or an array of keys, places options under an alternative heading | ||
when displaying usage instructions, e.g., | ||
```js | ||
var yargs = require('yargs')(['--help']) | ||
.help('help') | ||
.group('batman', 'Heroes:') | ||
.describe('batman', "world's greatest detective") | ||
.wrap(null) | ||
.argv | ||
``` | ||
*** | ||
Heroes: | ||
--batman world's greatest detective | ||
Options: | ||
--help Show help [boolean] | ||
.help([option, [description]]) | ||
@@ -739,2 +760,3 @@ ------------------------------ | ||
* **pt:** Portuguese. | ||
* **pt_BR:** Brazilian Portuguese. | ||
* **zh:** Chinese. | ||
@@ -831,2 +853,3 @@ * **pirate:** American Pirate. | ||
- `desc`/`describe`/`description`: string, the option description for help content, see [`describe()`](#describe) | ||
- `group`: string, when displaying usage instructions place the option under an alternative group heading, see [`group()`](#group) | ||
- `nargs`: number, specify how many arguments should be consumed for the option, see [`nargs()`](#nargs) | ||
@@ -1109,3 +1132,3 @@ - `requiresArg`: boolean, require the option be specified with a value, see [`requiresArg()`](#requiresArg) | ||
With [npm](http://github.com/isaacs/npm), just do: | ||
With [npm](https://github.com/npm/npm), just do: | ||
@@ -1136,5 +1159,5 @@ npm install yargs | ||
[coveralls-image]: https://img.shields.io/coveralls/bcoe/yargs.svg | ||
[npm-url]: https://npmjs.org/package/yargs | ||
[npm-url]: https://www.npmjs.com/package/yargs | ||
[npm-image]: https://img.shields.io/npm/v/yargs.svg | ||
[windows-url]: https://ci.appveyor.com/project/bcoe/yargs | ||
[windows-image]: https://img.shields.io/appveyor/ci/bcoe/yargs/master.svg?label=Windows%20Tests |
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
140328
20
1883
1159
Updateddecamelize@^1.1.1