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

Poll: Enhancements to global options #1551

Closed
shadowspawn opened this issue Jun 27, 2021 · 11 comments
Closed

Poll: Enhancements to global options #1551

shadowspawn opened this issue Jun 27, 2021 · 11 comments

Comments

@shadowspawn
Copy link
Collaborator

shadowspawn commented Jun 27, 2021

Commander supports global options by declaring them on the program. This is flexible, but Commander does not offer any additional support to make them easier to use as a programmer or find them as a user. Example program with current behaviour:

program
  .option('-g, --global');

program.command('sub')
  .option('-l, --local')
  .action((options, sub) => {
    console.log('subcommand options: %o', options);
    console.log('global options: %o', program.opts());
  });

program.parse();
$ node example.js --global sub --local
subcommand options: { local: true }
global options: { global: true }
$  node example.js help sub
Usage: example sub [options]

Options:
  -l, --local
  -h, --help   display help for command

Related: #243 #476 #905 #1024 (comment) #1078 #1426 #1631

What additional support would you like? (I am wondering what is most popular and useful, not planning to add everything!)

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jun 27, 2021

  1. An explicit way to access combined global and local options from action handler, without needing to use program variable.

This could be a parameter to .opts(), or a separate routine.

console.log('combined options: %o', sub.opts({ includeGlobals: true }));

Add 👍 reaction if you would like something like this.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jun 27, 2021

  1. Configuration so .opts() and the options passed to the action handler always include combined global and local options.
program.includeGlobalsInOptions();

Add 👍 reaction if you would like something like this.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jun 27, 2021

  1. A way to show the global options in the help for a subcommand.
program.includeGlobalOptionsInHelp();
$  node example.js help sub
Usage: example sub [options]

Options:
  -l, --local
  -h, --help   display help for command

Global Options:
  -g, --global

Add 👍 reaction if you would like something like this.
Add 🚀 reaction too if you think this should be the default behaviour.

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jun 27, 2021

  1. A way to declare a common option that is actually added directly to (all) the subcommands, rather than to the program. This is a different sort of "global" option than in the other examples, but has come up in some comments.
program.commonOption('-l, --local');

Add 👍 reaction if you would like something like this.

@percenuage
Copy link

It's a mandatory feature and should be implemented soon :).

@binyamin
Copy link

@shadowspawn what is the time span for this poll?

@shadowspawn
Copy link
Collaborator Author

Counts at 2021-12-21.

  1. An explicit way to access combined global and local options from action handler, without needing to use program variable.
    8 👍

  2. Configuration so .opts() and the options passed to the action handler always include combined global and local options.
    3 👍

  3. A way to show the global options in the help for a subcommand.
    4 👍 5 🚀 (6 people total)

  4. A way to declare a common option that is actually added directly to (all) the subcommands, rather than to the program.
    10 👍

Thanks for the feedback.

@shadowspawn
Copy link
Collaborator Author

@binyamin

what is the time span for this poll?

I wasn't working on global options, and two of the options have been tracking with similar numbers of votes, so I had just left the poll open!

@shadowspawn
Copy link
Collaborator Author

Opened a draft PR for .addCommonOption() #1670

FYI: @rhyslbw @GerkinDev @WinterWolf98 @phi0411141 @kasperisager @zecka @mikemilano @aprat84 @ramoncarreras @DavidDudson

@shadowspawn
Copy link
Collaborator Author

shadowspawn commented Jan 4, 2022

Opened a draft PR for .opts({ includeGlobals: true }) #1671

Opened a draft PR for .optsWithGlobals() #1671

FYI: @shivanshs9 @GerkinDev @gralka @kuncevic @guillaumeLamanda @mikemilano @sureshkmit @binyamin

@shadowspawn
Copy link
Collaborator Author

Opened a PR to optionally show global options in the help: #1828

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

3 participants