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

How to get global options in executable subcommand? #2308

Open
JounQin opened this issue Jan 8, 2025 · 1 comment
Open

How to get global options in executable subcommand? #2308

JounQin opened this issue Jan 8, 2025 · 1 comment

Comments

@JounQin
Copy link

JounQin commented Jan 8, 2025

// main.js

program
  .option('-f, --force [boolean]')
  .command('new', 'scaffolding')

program.command('dev', function() {
  console.log(this.optsWithGlobals().force) // works as expected
})

program.parse(progress.argv)
// cli-new.js

// `--force` options unavailable in `progress.argv`

I know there is passThroughOptions, but when I enable it, cli dev --force will stop working in favor of cli --force dev...

@shadowspawn
Copy link
Collaborator

There isn't any built-in support for passing global options through to executable subcommands. As in your example, there is support for globals in commands with action-handlers.

Defining environment variables might be one way of passing through the information.

Past related issues: #563 #1137

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

No branches or pull requests

2 participants