Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: variadic arguments error parsing #155

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xueelf
Copy link

@xueelf xueelf commented Apr 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant