protected function getSelectedProjects(InputInterface $input)
    {
        $projectList = $input->getOption('projects');

        /** @var \Platformsh\Cli\Service\Identifier $identifier */
        $identifier = $this->getService('identifier');

        if (!empty($projectList)) {
            $missing = [];
            $selected = [];
            foreach ($this->splitProjectList($projectList) as $projectId) {
                try {
                    $result = $identifier->identify($projectId);
                } catch (InvalidArgumentException $e) {
                    $missing[] = $projectId;
                    continue;
                }
                $project = $this->api()->getProject($result['projectId'], $result['host']);
                if ($project !== false) {
                    $selected[$project->id] = $project;
                } else {
                    $missing[] = $projectId;
                }
            }
            if (!empty($missing)) {
                $this->stdErr->writeln(sprintf('Project ID(s) not found: <error>%s</error>', implode(', ', $missing)));
                return false;
            }

            return $selected;
        }

        if (!$input->isInteractive()) {
            $this->stdErr->writeln('In non-interactive mode, the --projects option must be specified.');
            return false;
        }

        /** @var \Platformsh\Cli\Service\Shell $shell */
        $shell = $this->getService('shell');
        if (!$shell->commandExists('dialog')) {
            $this->stdErr->writeln('The "dialog" utility is required for interactive use.');
            $this->stdErr->writeln('You can specify projects via the --projects option.');
            return false;
        }

        $projects = $this->getAllProjects($input);
        $projectOptions = [];
        foreach ($projects as $project) {
            $projectOptions[$project->id] = $project->title ?: $project->id;
        }

        $projectIds = $this->showDialogChecklist($projectOptions, 'Choose one or more projects');
        if (empty($projectIds)) {
            return false;
        }
        $selected = array_intersect_key($projects, array_flip($projectIds));
        $this->stdErr->writeln('Selected project(s): ' . implode(',', array_keys($selected)));
        $this->stdErr->writeln('');

        return $selected;
    }
protected function getSelectedProjects(InputInterface $input)
    {
        $projectList = $input->getOption('projects');

        /** @var \Platformsh\Cli\Service\Identifier $identifier */
        $identifier = $this->getService('identifier');

        if (!empty($projectList)) {
            $missing = [];
            $selected = [];
            foreach ($this->splitProjectList($projectList) as $projectId) {
                try {
                    $result = $identifier->identify($projectId);
                } catch (InvalidArgumentException $e) {
                    $missing[] = $projectId;
                    continue;
                }
                $project = $this->api()->getProject($result['projectId'], $result['host']);
                if ($project !== false) {
                    $selected[$project->id] = $project;
                } else {
                    $missing[] = $projectId;
                }
            }
            if (!empty($missing)) {
                $this->stdErr->writeln(sprintf('Project ID(s) not found: <error>%s</error>', implode(', ', $missing)));
                return false;
            }

            return $selected;
        }

        if (!$input->isInteractive()) {
            $this->stdErr->writeln('In non-interactive mode, the --projects option must be specified.');
            return false;
        }

        /** @var \Platformsh\Cli\Service\Shell $shell */
        $shell = $this->getService('shell');
        if (!$shell->commandExists('dialog')) {
            $this->stdErr->writeln('The "dialog" utility is required for interactive use.');
            $this->stdErr->writeln('You can specify projects via the --projects option.');
            return false;
        }

        $projects = $this->getAllProjects($input);
        $projectOptions = [];
        foreach ($projects as $project) {
            $projectOptions[$project->id] = $project->title ?: $project->id;
        }

        $projectIds = $this->showDialogChecklist($projectOptions, 'Choose one or more projects');
        if (empty($projectIds)) {
            return false;
        }
        $selected = array_intersect_key($projects, array_flip($projectIds));
        $this->stdErr->writeln('Selected project(s): ' . implode(',', array_keys($selected)));
        $this->stdErr->writeln('');

        return $selected;
    }
protected function getSelectedProjects ( InputInterface $ input ) { $ projectList = $ input -> getOption ( 'projects' ) ; /** @var \Platformsh\Cli\Service\Identifier $identifier */ $ identifier = $ this -> getService ( 'identifier' ) ; if ( ! empty ( $ projectList ) ) { $ missing = [ ] ; $ selected = [ ] ; foreach ( $ this -> splitProjectList ( $ projectList ) as $ projectId ) { try { $ result = $ identifier -> identify ( $ projectId ) ; } catch ( InvalidArgumentException $ e ) { $ missing [ ] = $ projectId ; continue ; } $ project = $ this -> api ( ) -> getProject ( $ result [ 'projectId' ] , $ result [ 'host' ] ) ; if ( $ project !== false ) { $ selected [ $ project -> id ] = $ project ; } else { $ missing [ ] = $ projectId ; } } if ( ! empty ( $ missing ) ) { $ this -> stdErr -> writeln ( sprintf ( 'Project ID(s) not found: <error>%s</error>' , implode ( ', ' , $ missing ) ) ) ; return false ; } return $ selected ; } if ( ! $ input -> isInteractive ( ) ) { $ this -> stdErr -> writeln ( 'In non-interactive mode, the --projects option must be specified.' ) ; return false ; } /** @var \Platformsh\Cli\Service\Shell $shell */ $ shell = $ this -> getService ( 'shell' ) ; if ( ! $ shell -> commandExists ( 'dialog' ) ) { $ this -> stdErr -> writeln ( 'The "dialog" utility is required for interactive use.' ) ; $ this -> stdErr -> writeln ( 'You can specify projects via the --projects option.' ) ; return false ; } $ projects = $ this -> getAllProjects ( $ input ) ; $ projectOptions = [ ] ; foreach ( $ projects as $ project ) { $ projectOptions [ $ project -> id ] = $ project -> title ? : $ project -> id ; } $ projectIds = $ this -> showDialogChecklist ( $ projectOptions , 'Choose one or more projects' ) ; if ( empty ( $ projectIds ) ) { return false ; } $ selected = array_intersect_key ( $ projects , array_flip ( $ projectIds ) ) ; $ this -> stdErr -> writeln ( 'Selected project(s): ' . implode ( ',' , array_keys ( $ selected ) ) ) ; $ this -> stdErr -> writeln ( '' ) ; return $ selected ; }
Get the projects selected by the user.

Projects can be specified via the command-line option --projects (as a
list of project IDs) or, if possible, the user will be prompted with a
checklist via the 'dialog' utility.

@param InputInterface $input

@return \Platformsh\Client\Model\Project[]|false
An array of projects, or false on error.
Get the projects selected by the user .