-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2841eb3
commit 762af97
Showing
2 changed files
with
55 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kiboko\Cloud\Platform\Console\Command\Environment; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Question\Question; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
final class InitCommand extends Command | ||
{ | ||
public static $defaultName = 'environment:init'; | ||
|
||
protected function configure() | ||
{ | ||
$this->setDescription('Initialize the environment file in local workspace'); | ||
} | ||
|
||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$format = new SymfonyStyle($input, $output); | ||
$allLines = []; | ||
|
||
$serverAddress = $format->askQuestion(new Question('Server of your remote directory')); | ||
$newLine = 'SERVER_ADDRESS' . ': ' . $serverAddress . PHP_EOL; | ||
array_push($allLines, $newLine); | ||
|
||
$depPath = $format->askQuestion(new Question('Path of your remote directory on the server')); | ||
$newLine = 'DEPLOYMENT_PATH' . ': ' . $depPath . PHP_EOL; | ||
array_push($allLines, $newLine); | ||
|
||
$envDistPath = getcwd() . '/.env.dist'; | ||
if (file_exists($envDistPath)) { | ||
$envDist = parse_ini_file($envDistPath); | ||
foreach (array_keys($envDist) as $line) { | ||
$lineValue = $format->askQuestion(new Question('Value of ' . $line)); | ||
$newLine = $line . ': ' . $lineValue . PHP_EOL; | ||
array_push($allLines, $newLine); | ||
} | ||
} | ||
|
||
$newFile = fopen('.kloud.environent.yaml', 'w'); | ||
foreach ($allLines as $line) { | ||
fwrite($newFile, $line); | ||
} | ||
|
||
return 0; | ||
} | ||
} |