diff --git a/src/parser/parse.ts b/src/parser/parse.ts index 2d83b37f9..b3aa0c1e4 100644 --- a/src/parser/parse.ts +++ b/src/parser/parse.ts @@ -351,10 +351,9 @@ export class Parser flag.type === 'boolean' || flag.env || flag.default || 'defaultHelp' in flag || flagTokenMap.has(name)) + .filter(([name, flag]) => flag.type === 'boolean' || flag.env || flag.default !== undefined || 'defaultHelp' in flag || flagTokenMap.has(name)) // match each possible flag to its token, if there is one .map(([name, flag]): FlagWithStrategy => ({inputFlag: {name, flag}, tokens: flagTokenMap.get(name)})) .map(fws => addValueFunction(fws)) diff --git a/test/parser/parse.test.ts b/test/parser/parse.test.ts index e65f80aa5..c1246938d 100644 --- a/test/parser/parse.test.ts +++ b/test/parser/parse.test.ts @@ -971,6 +971,25 @@ See more help with --help`) expect(out.args).to.deep.include({baz: false}) }) + it('accepts falsy flags', async () => { + const out = await parse([], { + flags: { + foo1: Flags.string({default: ''}), + foo2: Flags.string({default: '0'}), + foo3: Flags.string({default: 'false'}), + foo4: Flags.string({default: 'undefined'}), + bar: Flags.integer({default: 0}), + baz: Flags.boolean({default: false}), + }, + }) + expect(out.flags).to.deep.include({foo1: ''}) + expect(out.flags).to.deep.include({foo2: '0'}) + expect(out.flags).to.deep.include({foo3: 'false'}) + expect(out.flags).to.deep.include({foo4: 'undefined'}) + expect(out.flags).to.deep.include({bar: 0}) + expect(out.flags).to.deep.include({baz: false}) + }) + it('default as function', async () => { const out = await parse([], { args: {baz: Args.string({default: async () => 'BAZ'})},