From 8d9d9addcc901d42badbadb059b6ef0ff22d8744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sat, 31 Dec 2016 17:15:46 -0300 Subject: [PATCH] [Nostromo] Commands for listing configuration --- .../Command/BuiltIn/Config/DumpCommand.php | 54 +++++++++++++++ .../BuiltIn/Config/EnvironmentsCommand.php | 69 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/Mage/Command/BuiltIn/Config/DumpCommand.php create mode 100644 src/Mage/Command/BuiltIn/Config/EnvironmentsCommand.php diff --git a/src/Mage/Command/BuiltIn/Config/DumpCommand.php b/src/Mage/Command/BuiltIn/Config/DumpCommand.php new file mode 100644 index 0000000..d5dfc56 --- /dev/null +++ b/src/Mage/Command/BuiltIn/Config/DumpCommand.php @@ -0,0 +1,54 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Command\BuiltIn\Config; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Mage\Command\AbstractCommand; + +/** + * Command for Dumping the Configuration + * + * @author Andrés Montañez + */ +class DumpCommand extends AbstractCommand +{ + /** + * Configure the Command + */ + protected function configure() + { + $this + ->setName('config:dump') + ->setDescription('Dumps the Magallanes configuration') + ; + } + + /** + * Execute the Command + * + * @param InputInterface $input + * @param OutputInterface $output + * @return int|mixed + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln('Starting Magallanes'); + $output->writeln(''); + + $output->writeln(sprintf('%s', var_export($this->runtime->getConfiguration(), true))); + + $output->writeln(''); + $output->writeln('Finished Magallanes'); + + return 0; + } +} diff --git a/src/Mage/Command/BuiltIn/Config/EnvironmentsCommand.php b/src/Mage/Command/BuiltIn/Config/EnvironmentsCommand.php new file mode 100644 index 0000000..5d6ba2f --- /dev/null +++ b/src/Mage/Command/BuiltIn/Config/EnvironmentsCommand.php @@ -0,0 +1,69 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Command\BuiltIn\Config; + +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\Table; +use Mage\Command\AbstractCommand; + +/** + * Command for listing all the Environments + * + * @author Andrés Montañez + */ +class EnvironmentsCommand extends AbstractCommand +{ + /** + * Configure the Command + */ + protected function configure() + { + $this + ->setName('config:environments') + ->setDescription('List all Magallanes configured Environments') + ; + } + + /** + * Execute the Command + * + * @param InputInterface $input + * @param OutputInterface $output + * @return int|mixed + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $output->writeln('Starting Magallanes'); + $output->writeln(''); + + $table = new Table($output); + $table->setHeaders(['Environment', 'Branch', 'User', 'Hosts']); + + $configuration = $this->runtime->getConfigOptions('environments'); + foreach ($configuration as $environment => $config) { + $row = [$environment]; + + $row[] = (isset($config['user']) ? $config['user'] : '-'); + $row[] = (isset($config['branch']) ? $config['branch'] : '-'); + $row[] = (isset($config['hosts']) ? implode(PHP_EOL, $config['hosts']) : '-'); + + $table->addRow($row); + } + + $table->render(); + + $output->writeln(''); + $output->writeln('Finished Magallanes'); + + return 0; + } +}