Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply coercions to default options #65

Merged
merged 1 commit into from Nov 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -279,8 +279,8 @@ function parse (args, opts) {
setConfig(argv)
setConfigObjects()
applyEnvVars(argv, false)
applyCoercions(argv)
applyDefaultsAndAliases(argv, flags.aliases, defaults)
applyCoercions(argv)

// for any counts either not in args or without an explicit default, set to 0
Object.keys(flags.counts).forEach(function (key) {
Expand Down
12 changes: 12 additions & 0 deletions test/yargs-parser.js
Expand Up @@ -1992,6 +1992,18 @@ describe('yargs-parser', function () {
parsed.foo.bar.should.equal('nananana, batman!')
})

it('applies coercion to defaults', function () {
var parsed = parser([], {
default: { foo: 'bar' },
coerce: {
foo: function (val) {
return val.toUpperCase()
}
}
})
parsed.foo.should.equal('BAR')
})

it('applies coercion function to an implicit array', function () {
var parsed = parser(['--foo', '99', '-f', '33'], {
coerce: {
Expand Down