-
-
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
[question] Reusing options between subcommands and 'main' #1750
Comments
A quick answer (time limited). Options on the program are "global" and get processed when calling a subcommand, so the program consumes your required option and the subcommand does not see it. To get the behaviour you want, add a subcommand (like (Similar previous issue: #1616) |
Apologies, I did try to search beforehand. Thank you for the solution and rapid response! |
I can 'reuse' commands between subcommands nicely, which populates the options in the call backs as expected
And when I run help for each I see as expected;
However, if i try and reuse options between a sub command and the 'main' program;
then the sub commands will always complain of the missing requiredOption - even if it is passed
I can work around this my making the 'main' program a subcommand (like 'start'), but I would prefer if I didn't have to invoke a subcommand just to start the main program.
I'm not sure I am creating the 'main' program correctly though. I tried
new Command()
but with the same outcome. I also tried two separate command instances with twoparseAsync(process.argv)
calls (one for 'main' and one for the commands), but then commander doesn't register the commands in the second instance.The text was updated successfully, but these errors were encountered: