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
Extra arguments passed to non-variadic command are swallowed #749
Comments
Here's a simple example:
Call this with:
No warning. And the value "extra" is nowhere to be seen in the model except in rawArgs. |
The open question is whether we should consider these extra arguments an error condition or we should simply pass them to the action to handle. I've implemented it as an extra argument, though the code could easily repurposed. |
Here's another example: cli
.arguments('<command> [args...]')
.option('-h, --host <host>', 'The host on which the server should listen')
.option('-p, --port <port>', 'The port number on which the server should listen')
.action((command) => {
runCommand(command, args, cli.host, cli.port)
})
.parse(process.argv); Called with The '-v' is swallowed. I worked around the issue by looking for command in the rawArgs array then slicing from the index. |
I'm having this problem in an app I'm developing right now. I expected it to be an error to pass extra arguments, but I can't even detect them unless there's 2 extra instead of just 1 extra, which is odd: |
I was chasing some different issues, and independently came to same conclusion as @mojavelinux:
Working on this currently. |
v4.0.0-0 prerelease published: #1067 |
v4.0.0 has been released with a fix for program.args which was getting the command appended (matching the arguments passed to the action handler). |
If an action-based command does not have a variadic argument, extra arguments supplied by the user are swallowed. I would expect either for the command to exit with an error, or for those extra arguments to be passed to the callback method so they can be handled appropriately.
The root of the problem is that the program is overwriting the extra entry in the args array.
The text was updated successfully, but these errors were encountered: