-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Need a hook or event to set process.env before _parseOptionsEnv
#1762
Comments
It may be a |
For interest, what didn't work using the |
In my use case, async support is not necessary. program.addOption(new Option('--env <env>', 'env file').default('.env'))
.on('option:env', () => {
console.log('option:env event emit');
}); This event will only fire when the env parameter is explicitly specified, default value does not trigger the event. node dist/main.js --env .env.production # trigger
node dist/main.js # default value .env not trigger |
Released in Commander v9.4.0 |
Hallo,
Is there any way to set environment variables before
_parseOptionsEnv
function?my use case is to read
.env
file viadotenv
and set environment variables before all subcommands are executed.The dotenv file can be specified, and I am use
enablePositionalOptions
to process options.The issue is
preAction
hook are emit after_parseOptionsEnv
function, this will causenew Option().env('SOME_ENV')
not to perform as expected.I also tried the
option:env
event, but it doesn't solve the problem perfectly either.I searched relevant issues and stackoverflow as much as possible, but no solution found.
Thanks.
The text was updated successfully, but these errors were encountered: