Skip to content
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions src/Command/Tunnel/TunnelOpenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct(private readonly Api $api, private readonly Config $
protected function configure(): void
{
$this->addOption('gateway-ports', 'g', InputOption::VALUE_NONE, 'Allow remote hosts to connect to local forwarded ports');
$this->addOption('json', null, InputOption::VALUE_NONE, 'Outputs tunnel information in JSON on stdout');
$this->selector->addProjectOption($this->getDefinition());
$this->selector->addEnvironmentOption($this->getDefinition());
$this->selector->addAppOption($this->getDefinition());
Expand Down Expand Up @@ -122,6 +123,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$error = false;
$processIds = [];
$tunnels = [];
foreach ($relationships as $name => $services) {
foreach ($services as $key => $service) {
$service['_relationship_name'] = $name;
Expand All @@ -136,6 +138,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$relationshipString,
$this->tunnelManager->getUrl($openTunnelInfo),
));
$tunnels[$relationshipString] = ['relationship' => $relationshipString, 'url' => $this->tunnelManager->getUrl($tunnel),];
continue;
}

Expand Down Expand Up @@ -175,6 +178,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$relationshipString,
$this->tunnelManager->getUrl($tunnel),
));
$tunnels[$relationshipString] = ['relationship' => $relationshipString, 'url' => $this->tunnelManager->getUrl($tunnel),];

$processIds[] = $pid;
}
Expand All @@ -199,6 +203,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
}

if ($input->getOption('json')) {
$output->writeln(json_encode(['tunnels' => $tunnels], JSON_THROW_ON_ERROR));
}

$processManager->killParent($error);

$processManager->monitor($log);
Expand Down
10 changes: 8 additions & 2 deletions src/Command/Tunnel/TunnelSingleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ public function __construct(private readonly Api $api, private readonly Question
protected function configure(): void
{
$this
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The local port');
$this->addOption('gateway-ports', 'g', InputOption::VALUE_NONE, 'Allow remote hosts to connect to local forwarded ports');
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The local port')
->addOption('gateway-ports', 'g', InputOption::VALUE_NONE, 'Allow remote hosts to connect to local forwarded ports')
->addOption('json', null, InputOption::VALUE_NONE, 'Outputs tunnel information in JSON on stdout')
;
$this->selector->addProjectOption($this->getDefinition());
$this->selector->addEnvironmentOption($this->getDefinition());
$this->selector->addAppOption($this->getDefinition());
Expand Down Expand Up @@ -146,6 +148,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->stdErr->writeln('');

if ($input->getOption('json')) {
$output->writeln(json_encode(['tunnel' => ['relationship' => $relationshipString, 'url' => $this->tunnelManager->getUrl($tunnel),]], JSON_THROW_ON_ERROR));
}

$processManager->monitor($this->stdErr);

return $process->isSuccessful() ? 0 : 1;
Expand Down
Loading