Skip to content

Commit 3bb55d9

Browse files
committed
#12 : refacto
1 parent 762af97 commit 3bb55d9

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

Diff for: bin/kloud

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ $app->addCommands([
6060
__DIR__ . '/../compose/',
6161
))->setAliases(['upgrade']),
6262

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

6666
$app->run(new ArgvInput($argv), new ConsoleOutput());

Diff for: src/Platform/Console/Command/Environment/InitCommand.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Console\Question\Question;
1111
use Symfony\Component\Console\Style\SymfonyStyle;
12+
use Symfony\Component\Yaml\Yaml;
1213

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

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

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

3534
$envDistPath = getcwd() . '/.env.dist';
3635
if (file_exists($envDistPath)) {
3736
$envDist = parse_ini_file($envDistPath);
3837
foreach (array_keys($envDist) as $line) {
3938
$lineValue = $format->askQuestion(new Question('Value of ' . $line));
40-
$newLine = $line . ': ' . $lineValue . PHP_EOL;
41-
array_push($allLines, $newLine);
39+
$allLines[$line] = $lineValue;
4240
}
4341
}
4442

45-
$newFile = fopen('.kloud.environent.yaml', 'w');
46-
foreach ($allLines as $line) {
47-
fwrite($newFile, $line);
48-
}
43+
$yaml = Yaml::dump($allLines);
44+
file_put_contents('.kloud.environent.yaml', $yaml);
4945

5046
return 0;
5147
}

0 commit comments

Comments
 (0)