Skip to content

[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

Conversation

alexndlm
Copy link
Contributor

Q A
Branch? 6.4
Bug fix? no
New feature? yes
Deprecations? no
Issues
License MIT

@alexndlm
Copy link
Contributor Author

@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')
Copy link

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.

Copy link
Contributor Author

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')) {
Copy link

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');

Copy link
Contributor Author

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')
Copy link

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.

Copy link
Contributor Author

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'] ?? [];
Copy link

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.

Copy link
Contributor Author

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');
Copy link

@ghost ghost Nov 12, 2023

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?

Copy link
Contributor Author

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.

@alexndlm alexndlm requested a review from a user November 13, 2023 06:58
@nicolas-grekas
Copy link
Member

What about closing this PR in favor of #52638?

@alexndlm
Copy link
Contributor Author

I don't mind.

@alexndlm alexndlm closed this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants