-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
"error: unknown command" when using addCommand #2212
Comments
The problem is Instead of const subCommand = new Command("createfunction <name>")
.description("Create a new function")
... try const subCommand = new Command("createfunction")
.argument('<name>')
.description("Create a new function")
... |
Thanks, that worked! Is it expected then that specifying the name and argument together appears to work without any errors, and even lists the command in the |
It isn't designed to work that way, it is is just how it works out. The command ends up with a very confusing name of % node index.js 'createfunction <name>'
Executing createfunction command {} If this trips up many people, we could have it throw an error when arguments are included inline for |
A PR was suggested to make this work in #1941 but at that time I didn't want to do that. Thinking about other behaviours, |
(Thanks for the clear example code and description.) |
Ah, that makes sense. Hadn't realised that was what's happening since the way the command gets listed in the help output is the same.
Given that I didn't find any other mentions of people facing similar issues, I guess this isn't a common occurrence so I'm ok to close this issue - but I'll leave it to you or other maintainers to decide if it's worth updating it to make it consistent with how Commander handles other behaviours. |
This hasn't come up again in the last few months. People may be using Feel free to open a new issue if it comes up again, with new information and renewed interest. Thank you for your contributions. |
When using
addCommand
to add a preconfigured command, the command is listed when running with the--help
flag, but fails with an "error: unknown command" message when trying to run the command. This happens with 12.1.0.I've created a sample implementation here: https://codesandbox.io/p/devbox/upbeat-aj-cxxmw2?file=%2Findex.js
Sample code
Output
If I configure the command inline, it works as expected:
The text was updated successfully, but these errors were encountered: