Skip to content

Commit 57594e6

Browse files
authored
Fix support for --force in winter:env (#1368)
1 parent c37362d commit 57594e6

1 file changed

Lines changed: 19 additions & 31 deletions

File tree

modules/system/console/WinterEnv.php

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<?php namespace System\Console;
1+
<?php
2+
3+
namespace System\Console;
24

35
use App;
46
use Winter\Storm\Parse\EnvFile;
@@ -16,11 +18,21 @@
1618
*/
1719
class WinterEnv extends Command
1820
{
21+
use \Illuminate\Console\ConfirmableTrait;
22+
1923
/**
2024
* The console command name.
2125
*/
2226
protected $name = 'winter:env';
2327

28+
/**
29+
* The name and signature of the console command.
30+
*
31+
* @var string
32+
*/
33+
protected $signature = 'winter:env
34+
{--force : Force the operation to run when in production}';
35+
2436
/**
2537
* The console command description.
2638
*/
@@ -55,8 +67,12 @@ public function __construct()
5567
public function handle(): int
5668
{
5769
if (
58-
file_exists($this->laravel->environmentFilePath())
59-
&& !$this->confirmToProceed()
70+
!$this->confirmToProceed(
71+
'The .env file already exists. Proceeding may overwrite some values!',
72+
function () {
73+
return file_exists($this->laravel->environmentFilePath()) && $this->getLaravel()->environment() === 'production';
74+
}
75+
)
6076
) {
6177
return 1;
6278
}
@@ -69,34 +85,6 @@ public function handle(): int
6985
return 0;
7086
}
7187

72-
/**
73-
* Confirm before proceeding with the action.
74-
*
75-
* This method only asks for confirmation in production.
76-
*
77-
* @param string $warning
78-
* @param \Closure|bool|null $callback
79-
* @return bool
80-
*/
81-
public function confirmToProceed($warning = 'Application In Production!', $callback = null)
82-
{
83-
if ($this->hasOption('force') && $this->option('force')) {
84-
return true;
85-
}
86-
87-
$this->alert('The .env file already exists. Proceeding may overwrite some values!');
88-
89-
$confirmed = $this->confirm('Do you really wish to run this command?');
90-
91-
if (!$confirmed) {
92-
$this->comment('Command Canceled!');
93-
94-
return false;
95-
}
96-
97-
return true;
98-
}
99-
10088
/**
10189
* Get the full path of a config file
10290
* @param string $config

0 commit comments

Comments
 (0)