Skip to content

Commit

Permalink
changed check funtionality slightly see #76
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Feb 12, 2015
1 parent 0d8f791 commit 670110f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,8 @@ As an example, here's how the npm cli might document some of its commands:
```js
var argv = require('yargs')
.usage('npm <command>')
.command('install', 'install a package!')
.command('publish', 'publish a new version of your package')
.command('install', 'tis a mighty fine package to install')
.command('publish', 'shiver me timbers, should you be sharing all that')
.argv;
```

Expand Down Expand Up @@ -516,7 +516,7 @@ Check that certain conditions are met in the provided arguments.

`fn` is called with two arguments, the parsed `argv` hash and an array of options and their aliases.

If `fn` throws or returns `false`, show the thrown error, usage information, and
If `fn` throws or returns a non-truthy value, show the thrown error, usage information, and
exit.

.fail(fn)
Expand Down
2 changes: 1 addition & 1 deletion lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module.exports = function (yargs, usage) {
checks.forEach(function (f) {
try {
var result = f(argv, aliases);
if (result === false) {
if (!result) {
usage.fail('Argument check failed: ' + f.toString());
} else if (typeof result === 'string') {
usage.fail(result);
Expand Down
1 change: 1 addition & 0 deletions test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ describe('usage tests', function () {
.check(function (argv) {
if (!('x' in argv)) throw 'You forgot about -x';
if (!('y' in argv)) throw 'You forgot about -y';
else return true;
})
.argv;
});
Expand Down

0 comments on commit 670110f

Please sign in to comment.