tj/commander.js

[Bug] Unexpected arguments ignored

Opened this issue · 2 comments

Hi,

When passing more arguments to a command than it expects, the command is executed without error, receiving only the expected arguments.

It would be nice to throw an error instead, preventing potantially wrong actions/results unforeseen by the user.

One particular case is when an argument is a name/title/label, in which the user may include spaces while forgetting quotes.

On the other hand, I wonder if it would be possible, when said argument is the last (or only) one, to optionally put everything automatically in it, kinda like the spread operator in JS (but still outputting a string) ?

Thanks

It would be nice to throw an error instead, preventing potantially wrong actions/results unforeseen by the user.

You can make this an error by calling .allowExcessArguments(false).

On the other hand, I wonder if it would be possible, when said argument is the last (or only) one, to optionally put everything automatically in it, kinda like the spread operator in JS (but still outputting a string) ?

You can explicitly collect the remaining arguments by declaring the last one as variadic like `.argument('[more-args...]').

Also, all of the arguments are available using cmd.args. This includes both the declared and the excess arguments.

Oh, I'm sorry I didn't find these beforehand. 😅

allowExcessArguments(false)

I'd like to request this to be default though, for security reasons.

Thanks