protected function selectEnvironment($environmentId = null)
{
if (!empty($environmentId)) {
$environment = $this->api()->getEnvironment($environmentId, $this->project, null, true);
if (!$environment) {
throw new \RuntimeException('Specified environment not found: ' . $environmentId);
}
return $environment;
}
// If no ID is specified, try to auto-detect the current environment.
if ($environment = $this->getCurrentEnvironment($this->project)) {
return $environment;
}
if ($this->getProjectRoot()) {
$message = 'Could not determine the current environment.' . "\n" . 'Specify it manually using --environment (-e).';
} else {
$message = 'No environment specified.' . "\n" . 'Specify one using --environment (-e), or go to a project directory.';
}
throw new \RuntimeException($message);
}