-
-
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
[WIP] Forward subcommands (action-like subcommands) #1024
Conversation
Thanks @a-fas It will take me a while to have a look through this. I am interested in whether this can be made a default behaviour, rather than a special mode. Do you think that could be feasible with the approach you took, or did you discover certain behaviours mean you need to explicitly switch modes? (Asking a light question in case you have insights.) |
Hmmm, Not sure I clearly understood the question :) And what do you mean with "default behavior". However! Working on this feature I considered it more as a side-feature. But looking from a higher perspective I think I have one better idea. I'll post the full answer in the original issue (#764 ) as it maybe worth a wider discussion. |
Noticed a problem when using --help with a subcommand. Could just be local so im investigating, but basically calling |
372b7be
to
268886e
Compare
Sorry for long silence, had been rather busy. I reworked the code, this version seems much cleaner semantically to me. Have a look. @shadowspawn
|
I am looking forward to digging through this. Thanks @a-fas . I see several small things I had been wondering about too, good prompt to follow through with some small improvements. Like:
|
Not sure I understood the last point. Do you mean removing the commented |
No, I quoted that because I liked it. I have looked at the the |
Yeah, copy-paste is exactly what I had in mind with the example :) One further consideration regarding |
Short version: Yes. Long version I have been wondering that too since you first proposed an option collection routine. In addition I am wondering about a call to make it the default behaviour so it can be used when the action handler is only passed the opts and not the Command object (the new opt-in behaviour on develop branch). I expect people want it one way or the other most of the time. There is an ambiguity about what to do when option defined at multiple layers. Command line parsing works from parent down to children, but child could have a default value which still gets defined. I think parent value overriding child value matches the parsing, and the problem only comes up in a use-case which is not explicitly supported. This can go in a separate Pull Request. |
That is something I have been wondering about separately to unify the action-handler and executable-handler behaviours, and work more often the way people expect. I haven't worked through the details yet though, and recommend don't attempt the unified behaviour in this PR. One thing at a time... Related: #1088 Thanks for comment. |
Today I have been doing lots of reading of this and existing code and #245. I am going to try some ideas for a different approach which uses pieces of all of them. I'll see how it goes and report back... |
Quick thoughts from my side opts
separate Pull Request: sure 👍. This however makes unified behaviour of the output: sure, I also think it is a separate concern. |
Thanks for quick thoughts @a-fas collectAllOptions and override order: if Commander support positional options in the future, then child overriding parent and taking the most specific option makes sense, as per your logic. There isn't a way to tell where option value came from. |
Pull Request
Problem
Addressing #764, briefly:
collectAllOption
feature to cleanly collect command options from all levels of subcommands (mainly, however can be used a a clean copy listing all option values even those which were not specified)Solution
Command.forwardSubcommands
(code published in Subcommands syntax and usage #764)Command.collectAllOptions
Command.useSubcommand
- semantically cleaner version offorwardSubcommands
ChangeLog
Action-like subcommands: specify subcommands with callback actions without separate process spawning, see
use-subcommands.js
in examples and readSub commands (handlers)
section of the readme