Skip to content

Commit

Permalink
chore: upgrade yargs-parser (#633)
Browse files Browse the repository at this point in the history
* chore: upgrade yargs-parser
BREAKING CHANGE: coerce is now applied as a final step after other parsing is complete

* add documentation for breaking changes in yargs-parser@4

* fix: a few small editing nits

* fix: bump yargs-parser again
  • Loading branch information
bcoe committed Sep 30, 2016
1 parent ad3146f commit cc1224e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Expand Up @@ -461,10 +461,17 @@ command line for `key`.
The coercion function should accept one argument, representing the parsed value
from the command line, and should return a new value or throw an error. The
returned value will be used as the value for `key` (or one of its aliases) in
`argv`. If the function throws, the error will be treated as a validation
`argv`.

If the function throws, the error will be treated as a validation
failure, delegating to either a custom [`.fail()`](#fail) handler or printing
the error message in the console.

Coercion will be applied to a value after
all other modifications, such as [`.normalize()`](#normalize).

_Examples:_

```js
var argv = require('yargs')
.coerce('file', function (arg) {
Expand Down Expand Up @@ -495,6 +502,22 @@ var argv = require('yargs')
.argv
```

If you are using dot-notion or arrays, .e.g., `user.email` and `user.password`,
coercion will be applied to the final object that has been parsed:

```js
// --user.name Batman --user.password 123
// gives us: {name: 'batman', password: '[SECRET]'}
var argv = require('yargs')
.option('user')
.coerce('user', opt => {
opt.name = opt.name.toLowerCase()
opt.password = '[SECRET]'
return opt
})
.argv
```

.command(cmd, desc, [builder], [handler])
-----------------------------------------
.command(cmd, desc, [module])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -24,7 +24,7 @@
"which-module": "^1.0.0",
"window-size": "^0.2.0",
"y18n": "^3.2.1",
"yargs-parser": "^3.2.0"
"yargs-parser": "^4.0.2"
},
"devDependencies": {
"chai": "^3.4.1",
Expand Down

0 comments on commit cc1224e

Please sign in to comment.