-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Dotenv] Add --dotenv-path option to DotenvDumpCommand #52553
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
[Dotenv] Add --dotenv-path option to DotenvDumpCommand #52553
Conversation
alexndlm
commented
Nov 11, 2023
Q | A |
---|---|
Branch? | 6.4 |
Bug fix? | no |
New feature? | yes |
Deprecations? | no |
Issues | |
License | MIT |
@carsonbot find reviewer |
@@ -47,6 +47,7 @@ protected function configure(): void | |||
new InputArgument('env', null === $this->defaultEnv ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'The application environment to dump .env files for - e.g. "prod".'), | |||
]) | |||
->addOption('empty', null, InputOption::VALUE_NONE, 'Ignore the content of .env files') | |||
->addOption('dotenv-path', null, InputOption::VALUE_OPTIONAL, 'Path to dot-env files') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use .env
instead of dot-env
in the description as it's already in the other options/arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -66,7 +67,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |||
|
|||
$composerFile = $projectDir.'/composer.json'; | |||
$config += (is_file($composerFile) ? json_decode(file_get_contents($composerFile), true) : [])['extra']['runtime'] ?? []; | |||
$dotenvPath = $projectDir.'/'.($config['dotenv_path'] ?? '.env'); | |||
|
|||
if ($input->getOption('dotenv-path')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class would like the following notation more: $dotenvPath = $projectDir.'/'.($input->getOption('dotenv-path') ?? $config['dotenv_path'] ?? '.env');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -47,6 +47,7 @@ protected function configure(): void | |||
new InputArgument('env', null === $this->defaultEnv ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'The application environment to dump .env files for - e.g. "prod".'), | |||
]) | |||
->addOption('empty', null, InputOption::VALUE_NONE, 'Ignore the content of .env files') | |||
->addOption('dotenv-path', null, InputOption::VALUE_OPTIONAL, 'Path to .env files') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this is a path to .env file, not files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -66,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |||
|
|||
$composerFile = $projectDir.'/composer.json'; | |||
$config += (is_file($composerFile) ? json_decode(file_get_contents($composerFile), true) : [])['extra']['runtime'] ?? []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line looks like you can set dotenv_path
in your composer.json file:
"extra": {
"runtime": {
"dotenv_path": "some/path/.env"
}
}
In that case this PR would not be needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for cases when the .env file name contains an env name, like a local.env
, dev.env
, prod.env
.
@@ -66,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |||
|
|||
$composerFile = $projectDir.'/composer.json'; | |||
$config += (is_file($composerFile) ? json_decode(file_get_contents($composerFile), true) : [])['extra']['runtime'] ?? []; | |||
$dotenvPath = $projectDir.'/'.($config['dotenv_path'] ?? '.env'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have second thoughts on this. Maybe we should set the $config['dotenv_path']
if this option was passed to the command and then leave this line as it was before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it doesn't matter.
What about closing this PR in favor of #52638? |
I don't mind. |