Skip to content
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

Add way to collect inherited/global options from parents #1155

Closed
shadowspawn opened this issue Jan 23, 2020 · 2 comments
Closed

Add way to collect inherited/global options from parents #1155

shadowspawn opened this issue Jan 23, 2020 · 2 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jan 23, 2020

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 });
@shadowspawn shadowspawn changed the title Add way to get inherited/global options from parents Add way to collect inherited/global options from parents Jan 23, 2020
@shadowspawn
Copy link
Collaborator Author

Related historical: #243

@shadowspawn
Copy link
Collaborator Author

No activity in a month. I did some research and rethinking the higher level goals. Closing in favour of #1229.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant