protected function selectApp(InputInterface $input)
    {
        $appName = $input->getOption('app');
        if ($appName) {
            return $appName;
        }

        try {
            $apps = array_map(function (WebApp $app) {
                return $app->name;
            }, $this->api()->getCurrentDeployment($this->getSelectedEnvironment())->webapps);
            if (!count($apps)) {
                return null;
            }
        } catch (EnvironmentStateException $e) {
            if (!$e->getEnvironment()->isActive()) {
                throw new EnvironmentStateException(
                    sprintf('Could not find applications: the environment "%s" is not currently active.', $e->getEnvironment()->id),
                    $e->getEnvironment()
                );
            }
            throw $e;
        }

        $this->debug('Found app(s): ' . implode(',', $apps));
        if (count($apps) === 1) {
            $appName = reset($apps);
        } elseif ($input->isInteractive()) {
            /** @var \Platformsh\Cli\Service\QuestionHelper $questionHelper */
            $questionHelper = $this->getService('question_helper');
            $choices = array_combine($apps, $apps);
            $appName = $questionHelper->choose($choices, 'Enter a number to choose an app:');
        }

        $input->setOption('app', $appName);

        return $appName;
    }