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

fix: falsy arg default #40

Merged
merged 1 commit into from
Oct 17, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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