protected function selectProject($projectId = null, $host = null)
    {
        if (!empty($projectId)) {
            $this->project = $this->api()->getProject($projectId, $host);
            if (!$this->project) {
                throw new ConsoleInvalidArgumentException($this->getProjectNotFoundMessage($projectId));
            }

            $this->debug('Selected project: ' . $this->project->id);

            return $this->project;
        }

        $this->project = $this->getCurrentProject();
        if (!$this->project && isset($this->input) && $this->input->isInteractive()) {
            $projects = $this->api()->getProjects();
            if (count($projects) > 0 && count($projects) < 25) {
                $this->debug('No project specified: offering a choice...');
                $projectId = $this->offerProjectChoice($projects);

                return $this->selectProject($projectId);
            }
        }
        if (!$this->project) {
            throw new RootNotFoundException(
                "Could not determine the current project."
                . "\n\nSpecify it using --project, or go to a project directory."
            );
        }

        return $this->project;
    }