Add way to collect inherited/global options from parents #1155
Closed
Description
Problem
When there are global common options on the program, and subcommands using action handlers, there are options in two places. In a simple program you may have easy access to both the "program" and the "command", but that pattern is not always convenient, and does not scale very well to nested subcommands or to the action handler being passed just options.
Current:
program
.option('-g,--global')
.command('sub')
.option('-l,--local')
.action((cmd) => {
console.log(program.global); // using program
console.log(cmd.parent.global)); // using parent
console.log(cmd.local);
});
Possible Solution
@a-fas offered a routine or an option to .opt()
to collect all the options:
#1024 (comment)
Enhancing .opts()
is a nice idea. Adding this issue to make it visible as a possible enhancement.
e.g. trying some wording:
const opts1 = cmd.opts({ deep: true });
// or
const opts2 = cmd.opts({ collectAllOptions: true });