Platformsh\Cli\Command\Tunnel\TunnelCloseCommand::execute PHP Method

execute() protected method

protected execute ( Symfony\Component\Console\Input\InputInterface $input, Symfony\Component\Console\Output\OutputInterface $output )
$input Symfony\Component\Console\Input\InputInterface
$output Symfony\Component\Console\Output\OutputInterface
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->checkSupport();
        $tunnels = $this->getTunnelInfo();
        $allTunnelsCount = count($tunnels);
        if (!$allTunnelsCount) {
            $this->stdErr->writeln('No tunnels found.');
            return 1;
        }
        // Filter tunnels according to the current project and environment, if
        // available.
        if (!$input->getOption('all')) {
            $tunnels = $this->filterTunnels($tunnels, $input);
            if (!count($tunnels)) {
                $this->stdErr->writeln('No tunnels found. Use --all to close all tunnels.');
                return 1;
            }
        }
        /** @var \Platformsh\Cli\Helper\QuestionHelper $questionHelper */
        $questionHelper = $this->getHelper('question');
        $error = false;
        foreach ($tunnels as $tunnel) {
            $relationshipString = $this->formatTunnelRelationship($tunnel);
            $appString = $tunnel['projectId'] . '-' . $tunnel['environmentId'];
            if ($tunnel['appName']) {
                $appString .= '--' . $tunnel['appName'];
            }
            $questionText = sprintf("Close tunnel to relationship <comment>%s</comment> on %s?", $relationshipString, $appString);
            if ($questionHelper->confirm($questionText)) {
                if ($this->closeTunnel($tunnel)) {
                    $this->stdErr->writeln(sprintf('Closed tunnel to <info>%s</info> on %s', $relationshipString, $appString));
                } else {
                    $error = true;
                    $this->stdErr->writeln(sprintf('Failed closing tunnel to <error>%s</error> on %s', $relationshipString, $appString));
                }
            }
        }
        if (!$input->getOption('all') && count($tunnels) < $allTunnelsCount) {
            $this->stdErr->writeln('Use --all to close all tunnels.');
        }
        return $error ? 1 : 0;
    }
TunnelCloseCommand