Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
fix: falsy arg default (#40)
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
jdx authored Oct 17, 2018
1 parent af00006 commit 2e73b4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export class Parser<T extends ParserInput, TFlags extends OutputFlags<T['flags']
args[i] = token.input
}
} else {
if (arg.default) {
if ('default' in arg) {
if (typeof arg.default === 'function') {
args[i] = arg.default()
} else {
Expand Down
7 changes: 7 additions & 0 deletions test/parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ See more help with --help`)
expect(out.flags).to.deep.include({foo: 'bar'})
})

it('accepts falsy', () => {
const out = parse([], {
args: [{name: 'baz', default: false}],
})
expect(out.args).to.deep.include({baz: false})
})

it('default as function', () => {
const out = parse([], {
args: [{name: 'baz', default: () => 'BAZ'}],
Expand Down

0 comments on commit 2e73b4b

Please sign in to comment.