Skip to content

Commit

Permalink
#12 : refacto
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas43000 committed Sep 24, 2020
1 parent 762af97 commit 3bb55d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bin/kloud
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $app->addCommands([
__DIR__ . '/../compose/',
))->setAliases(['upgrade']),

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

$app->run(new ArgvInput($argv), new ConsoleOutput());
16 changes: 6 additions & 10 deletions src/Platform/Console/Command/Environment/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Yaml\Yaml;

final class InitCommand extends Command
{
Expand All @@ -25,27 +26,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
$allLines = [];

$serverAddress = $format->askQuestion(new Question('Server of your remote directory'));
$newLine = 'SERVER_ADDRESS' . ': ' . $serverAddress . PHP_EOL;
array_push($allLines, $newLine);
$allLines['SERVER_ADDRESS'] = $serverAddress;

$depPath = $format->askQuestion(new Question('Path of your remote directory on the server'));
$newLine = 'DEPLOYMENT_PATH' . ': ' . $depPath . PHP_EOL;
array_push($allLines, $newLine);
$allLines['DEPLOYMENT_PATH'] = $depPath;

$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);
$allLines[$line] = $lineValue;
}
}

$newFile = fopen('.kloud.environent.yaml', 'w');
foreach ($allLines as $line) {
fwrite($newFile, $line);
}
$yaml = Yaml::dump($allLines);
file_put_contents('.kloud.environent.yaml', $yaml);

return 0;
}
Expand Down

0 comments on commit 3bb55d9

Please sign in to comment.