From 36eb02f168eaa179e260010443fd33e526a94763 Mon Sep 17 00:00:00 2001 From: RasPhilCo Date: Wed, 9 Sep 2020 11:33:43 -0500 Subject: [PATCH] fix: accept integer 0 as valid arg input (#34) --- src/parser/validate.ts | 2 +- test/parser/validate.test.ts | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/parser/validate.ts b/src/parser/validate.ts index b8b522ff1..d17c09898 100644 --- a/src/parser/validate.ts +++ b/src/parser/validate.ts @@ -34,7 +34,7 @@ export function validate(parse: { } if (arg.required) { - if (!parse.output.argv[index]) { + if (!parse.output.argv[index] && parse.output.argv[index] as any as number !== 0) { missingRequiredArgs.push(arg) } } diff --git a/test/parser/validate.test.ts b/test/parser/validate.test.ts index 2f76271d3..85324f295 100644 --- a/test/parser/validate.test.ts +++ b/test/parser/validate.test.ts @@ -89,15 +89,20 @@ describe('validate', () => { required: true, }, }, - args: [], + args: [ + { + name: 'zero', + required: true, + }, + ], strict: true, context: {}, '--': true, } const output = { - args: {}, - argv: [], + args: {zero: 0}, + argv: [0], flags: {int: 0}, raw: [], metadata: {