cac
cac copied to clipboard
fix: variadic arguments error parsing
Although it is stated in the readme that variadic arguments can only the last parameter, there is no syntax check in the code.
Code
const cli = require('cac')()
cli
.command('parse [a] [...b] [...c] [d]', 'Command parse')
.action((a, b, c, d, options) => {
console.log(a)
console.log(b)
console.log(c)
console.log(d)
})
cli.parse()
Terminal
This code still works, but it doesn't work as expected
Current
$ node index.js parse a b c d
a
['b', 'c', 'd']
['c', 'd']
d
Improved
$ node index.js parse a b c d
CommandError: only the last argument can be variadic 'b'
(。・∀・)ノ゙ Will now directly throw an exception.