Skip to content

Commit

Permalink
#12 : add environment:init
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas43000 committed Sep 23, 2020
1 parent 2841eb3 commit 762af97
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/kloud
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ $app->addCommands([
__DIR__ . '/../config/',
__DIR__ . '/../compose/',
))->setAliases(['upgrade']),

(new Command\Environment\InitCommand())->setAliases(['env:init']),
]);

$app->run(new ArgvInput($argv), new ConsoleOutput());
$app->run(new ArgvInput($argv), new ConsoleOutput());
52 changes: 52 additions & 0 deletions src/Platform/Console/Command/Environment/InitCommand.php
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;
}
}

0 comments on commit 762af97

Please sign in to comment.