Skip to content

Commit

Permalink
fix: accept integer 0 as valid arg input (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo committed Sep 9, 2020
1 parent 60a3615 commit 36eb02f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/parser/validate.ts
Expand Up @@ -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)
}
}
Expand Down
11 changes: 8 additions & 3 deletions test/parser/validate.test.ts
Expand Up @@ -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: {
Expand Down

0 comments on commit 36eb02f

Please sign in to comment.