From 762af9760ef69380712e2369e497f9006580d421 Mon Sep 17 00:00:00 2001 From: nicolaschautard Date: Wed, 23 Sep 2020 15:04:58 +0200 Subject: [PATCH] #12 : add environment:init --- bin/kloud | 4 +- .../Command/Environment/InitCommand.php | 52 +++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/Platform/Console/Command/Environment/InitCommand.php diff --git a/bin/kloud b/bin/kloud index e5d5e24..3247b71 100755 --- a/bin/kloud +++ b/bin/kloud @@ -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()); \ No newline at end of file +$app->run(new ArgvInput($argv), new ConsoleOutput()); diff --git a/src/Platform/Console/Command/Environment/InitCommand.php b/src/Platform/Console/Command/Environment/InitCommand.php new file mode 100644 index 0000000..4a28f65 --- /dev/null +++ b/src/Platform/Console/Command/Environment/InitCommand.php @@ -0,0 +1,52 @@ +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; + } +}