9
9
use Symfony \Component \Console \Output \OutputInterface ;
10
10
use Symfony \Component \Console \Question \Question ;
11
11
use Symfony \Component \Console \Style \SymfonyStyle ;
12
+ use Symfony \Component \Yaml \Yaml ;
12
13
13
14
final class InitCommand extends Command
14
15
{
@@ -25,27 +26,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
25
26
$ allLines = [];
26
27
27
28
$ 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 ;
30
30
31
31
$ 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 ;
34
33
35
34
$ envDistPath = getcwd () . '/.env.dist ' ;
36
35
if (file_exists ($ envDistPath )) {
37
36
$ envDist = parse_ini_file ($ envDistPath );
38
37
foreach (array_keys ($ envDist ) as $ line ) {
39
38
$ lineValue = $ format ->askQuestion (new Question ('Value of ' . $ line ));
40
- $ newLine = $ line . ': ' . $ lineValue . PHP_EOL ;
41
- array_push ($ allLines , $ newLine );
39
+ $ allLines [$ line ] = $ lineValue ;
42
40
}
43
41
}
44
42
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 );
49
45
50
46
return 0 ;
51
47
}
0 commit comments