Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/Command/Tunnel/TunnelInfoCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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.');
Expand Down
Loading