Skip to content

Commit

Permalink
improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
talentlessguy committed Feb 4, 2024
1 parent fee046c commit fee3ed0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ export const handleArgParsing = <
for (const opt of requiredOptions) {
if (
!parsedArgs.find((arg) =>
arg[0] === opt.name || (opt.aliases || []).includes(arg[0])
arg[0] === opt.name || opt.aliases.includes(arg[0])
)
) {
throw new Error(`Argument ${opt.name} is required`)
}
}

for (const [arg, value] of parsedArgs) {
const opt = options.find((x) =>
x.name === arg || (x.aliases || []).includes(arg)
)
const opt = options.find((x) => x.name === arg || x.aliases.includes(arg))
const actualType = typeDetect(value)
if (!opt) throw new Error(`Unknown argument: ${arg}`)
if (actualType !== opt.type) {
Expand Down
16 changes: 16 additions & 0 deletions parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,20 @@ describe('handleArgParsing', () => {
)
}
})
it('throws if neither arg nor alias was passed', () => {
try {
handleArgParsing({
options: [{
name: 'test',
type: 'boolean',
required: true,
aliases: ['t'],
}],
}, [])
} catch (e) {
expect((e as Error).message).toEqual(
'Argument test is required',
)
}
})
})

0 comments on commit fee3ed0

Please sign in to comment.