diff --git a/src/Command/Tunnel/TunnelInfoCommand.php b/src/Command/Tunnel/TunnelInfoCommand.php index 77e3fa911e..58eed0f9d5 100644 --- a/src/Command/Tunnel/TunnelInfoCommand.php +++ b/src/Command/Tunnel/TunnelInfoCommand.php @@ -13,7 +13,8 @@ protected function configure() ->setName('tunnel:info') ->setDescription("View relationship info for SSH tunnels") ->addOption('property', 'P', InputOption::VALUE_REQUIRED, 'The relationship property to view') - ->addOption('encode', 'c', InputOption::VALUE_NONE, 'Output as base64-encoded JSON'); + ->addOption('encode', 'c', InputOption::VALUE_NONE, 'Output as base64-encoded JSON') + ->addOption('env', null, InputOption::VALUE_NONE, 'Output as a list of environment variables ("export" statements)'); $this->addProjectOption(); $this->addEnvironmentOption(); $this->addAppOption(); @@ -60,6 +61,29 @@ protected function execute(InputInterface $input, OutputInterface $output) return 1; } + if ($input->getOption('env')) { + if ($input->getOption('property') || $input->getOption('encode')) { + $this->stdErr->writeln('You cannot combine --env with --encode or --property.'); + return 1; + } + + $envPrefix = $this->config()->get('service.env_prefix'); + $output->writeln('export ' . $envPrefix . 'RELATIONSHIPS=' . base64_encode(json_encode($relationships))); + + foreach ($relationships as $name => $services) { + if (!isset($services[0])) { + continue; + } + foreach ($services[0] as $key => $value) { + if (is_scalar($value)) { + $output->writeln('export ' . strtoupper($name) . '_' . strtoupper($key) . '=' . $value); + } + } + } + + return 0; + } + if ($input->getOption('encode')) { if ($input->getOption('property')) { $this->stdErr->writeln('You cannot combine --encode with --property.');