Skip to content

Commit c79052b

Browse files
ssonalbcoe
authored andcommitted
feat: apply coercions to default options (#65)
1 parent 02c3545 commit c79052b

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ function parse (args, opts) {
279279
setConfig(argv)
280280
setConfigObjects()
281281
applyEnvVars(argv, false)
282-
applyCoercions(argv)
283282
applyDefaultsAndAliases(argv, flags.aliases, defaults)
283+
applyCoercions(argv)
284284

285285
// for any counts either not in args or without an explicit default, set to 0
286286
Object.keys(flags.counts).forEach(function (key) {

test/yargs-parser.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,6 +2004,18 @@ describe('yargs-parser', function () {
20042004
parsed.foo.bar.should.equal('nananana, batman!')
20052005
})
20062006

2007+
it('applies coercion to defaults', function () {
2008+
var parsed = parser([], {
2009+
default: { foo: 'bar' },
2010+
coerce: {
2011+
foo: function (val) {
2012+
return val.toUpperCase()
2013+
}
2014+
}
2015+
})
2016+
parsed.foo.should.equal('BAR')
2017+
})
2018+
20072019
it('applies coercion function to an implicit array', function () {
20082020
var parsed = parser(['--foo', '99', '-f', '33'], {
20092021
coerce: {

0 commit comments

Comments
 (0)