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

[Bug] Unexpected arguments ignored #2149

Open
KaKi87 opened this issue Feb 8, 2024 · 2 comments
Open

[Bug] Unexpected arguments ignored #2149

KaKi87 opened this issue Feb 8, 2024 · 2 comments

Comments

@KaKi87
Copy link

KaKi87 commented Feb 8, 2024

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

@shadowspawn
Copy link
Collaborator

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.

@KaKi87
Copy link
Author

KaKi87 commented Feb 9, 2024

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

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

No branches or pull requests

2 participants