Comparing version 3.8.0 to 3.9.0
## Change Log | ||
### v3.9.0 (2015/05/10 18:32 +00:00) | ||
- [#157](https://github.com/bcoe/yargs/pull/157) Merge pull request #157 from bcoe/command-yargs. allows handling of command specific arguments. Thanks for the suggestion @ohjames (@bcoe) | ||
- [#158](https://github.com/bcoe/yargs/pull/158) Merge pull request #158 from kemitchell/spdx-license. Update license format (@kemitchell) | ||
### v3.8.0 (2015/04/24 23:10 +00:00) | ||
@@ -4,0 +8,0 @@ - [#154](https://github.com/bcoe/yargs/pull/154) showHelp's method signature was misleading fixes #153 (@bcoe) |
30
index.js
@@ -70,2 +70,4 @@ var assert = require('assert'), | ||
completionOpt = null | ||
commandHandlers = {} | ||
self.parsed = false | ||
@@ -112,7 +114,13 @@ return self | ||
self.command = function (cmd, description) { | ||
self.command = function (cmd, description, fn) { | ||
usage.command(cmd, description) | ||
if (fn) commandHandlers[cmd] = fn | ||
return self | ||
} | ||
var commandHandlers = {} | ||
self.getCommandHandlers = function () { | ||
return commandHandlers | ||
} | ||
self.string = function (strings) { | ||
@@ -302,2 +310,3 @@ options.string.push.apply(options.string, [].concat(strings)) | ||
usage.version(ver) | ||
self.boolean(versionOpt) | ||
self.describe(versionOpt, msg || 'Show version number') | ||
@@ -310,2 +319,3 @@ return self | ||
helpOpt = opt | ||
self.boolean(opt) | ||
self.describe(opt, msg || 'Show help') | ||
@@ -393,4 +403,4 @@ return self | ||
var parsed = Parser(args, options), | ||
argv = parsed.argv, | ||
aliases = parsed.aliases | ||
argv = parsed.argv, | ||
aliases = parsed.aliases | ||
@@ -409,4 +419,14 @@ argv.$0 = self.$0 | ||
// if there's a handler associated with a | ||
// command defer processing to it. | ||
var handlerKeys = Object.keys(self.getCommandHandlers()) | ||
for (var i = 0, command; (command = handlerKeys[i]) !== undefined; i++) { | ||
if (~argv._.indexOf(command)) { | ||
self.getCommandHandlers()[command](self.reset()) | ||
return self.argv | ||
} | ||
} | ||
Object.keys(argv).forEach(function (key) { | ||
if (key === helpOpt) { | ||
if (key === helpOpt && argv[key]) { | ||
self.showHelp('log') | ||
@@ -416,3 +436,3 @@ if (exitProcess) { | ||
} | ||
} else if (key === versionOpt) { | ||
} else if (key === versionOpt && argv[key]) { | ||
usage.showVersion() | ||
@@ -419,0 +439,0 @@ if (exitProcess) { |
{ | ||
"name": "yargs", | ||
"version": "3.8.0", | ||
"version": "3.9.0", | ||
"description": "Light-weight option parsing with an argv hash. No optstrings attached.", | ||
@@ -91,3 +91,3 @@ "main": "./index.js", | ||
], | ||
"license": "MIT/X11", | ||
"license": "MIT", | ||
"engine": { | ||
@@ -94,0 +94,0 @@ "node": ">=0.4" |
@@ -504,9 +504,16 @@ yargs | ||
.command(cmd, desc) | ||
.command(cmd, desc, [fn]) | ||
------------------- | ||
Document the commands exposed by your application (stored in the `_` variable). | ||
Document the commands exposed by your application. | ||
As an example, here's how the npm cli might document some of its commands: | ||
use `desc` to provide a description for each command your application accepts (the | ||
values stored in `argv._`). | ||
Optionally, you can provide a handler `fn` which will be executed when | ||
a given command is provided. The handler will be executed with an instance | ||
of `yargs`, which can be used to compose nested commands. | ||
Here's an example of top-level and nested commands in action: | ||
```js | ||
@@ -516,3 +523,11 @@ var argv = require('yargs') | ||
.command('install', 'tis a mighty fine package to install') | ||
.command('publish', 'shiver me timbers, should you be sharing all that') | ||
.command('publish', 'shiver me timbers, should you be sharing all that', function (yargs) { | ||
argv = yargs.option('f', { | ||
alias: 'force', | ||
description: 'yar, it usually be a bad idea' | ||
}) | ||
.help('help') | ||
.argv | ||
}) | ||
.help('help') | ||
.argv; | ||
@@ -519,0 +534,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
Misc. License Issues
License(Experimental) A package's licensing information has fine-grained problems.
Found 1 instance in 1 package
100313
0
1244
923