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
Transfer settings in addCommand #1186
Conversation
This is not the model I have in mind. The original motivation for The intent is to allow adding subcommands that are defined and configured separately, and decouple the program and the subcommand. Two key problems with transferring all the private settings in addCommand are:
Note also: (I am starting to see |
Yes, i thought about maybe checking if a setting is present and non-default before overriding it like this: cmd._exitCallback = cmd._exitCallback !== null ? cmd._exitCallback : this._exitCallback; Easy to do for nullable settings, not so much for others. About nested subcommands, you can forbid using But i'm not invested in this PR in any way, this is just to explore and think about alternative solutions to the original issue. |
My planned starting point is no inheritance of settings from parent command to child subcommand using The two exceptions are default command, and hiding help. Considering the properties, as listed in other PR:
I didn't see these as being relevant to
This one should be supported as option when added, like with
Who decides whether the help is displayed, the parent or the child? My first thought is perhaps allow either to hide the help! So supported as option when added, like with
I think these are owned by the child although in practice the author will want them consistent. If the author wants to configure then in a non-standard way they are able to call helpOption and addHelpCommand in child or in parent, and possibly pass around or apply their preferred default settings outside Commander.
Owned by the child, but might be useful to inherit sometimes, not least because it is useful when writing tests. However, starting out with no inheritance. Like with help, author can configure themselves.
These two are a pair and the second one changes the code in the action handler. Definitely owned by child, and author can choose to configure themselves. |
Added
Agree. By the way, why can't you set or get default command name outside of adding new command though (like
Agree. In what way a command will be able to set |
Also can add private boolean fields const nested = new Command();
const sub = new Command();
const top = new Command();
sub.addCommand(nested, { inheritHelp: true }); // nested wants to keep its exit
top.addCommand(sub, { inheritHelp: true, inheritExit: true }); // sub doesn't care
// nested command will receive help from top command, but not exit |
I am going to keep Thank you for your contributions. |
Pull Request
Problem
Currently there is no way to transfer private settings (related to help, where options are stored, exit callback and so on) to a command added through
addCommand
. (Connected to discussion in #1185.)Solution
Transfer settings in
addCommand
. Can add an option toCommandOptions
(inheritSettings
or something) to conditionally transfer this settings with it being true by default incommand()
and false in direct call toaddCommand
.