Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update annotations to PHP8 attributes #26

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions src/LagoonCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace Drush\Commands\drupal_integrations;

use Consolidation\SiteAlias\SiteAliasManagerAwareTrait;
use Drush\Attributes as CLI;
use Drush\Commands\DrushCommands;
use Drush\Drush;
use Drush\Exceptions\CommandFailedException;
use Drush\SiteAlias\SiteAliasManagerAwareInterface;
use GuzzleHttp\Client;
use Symfony\Component\HttpKernel\Kernel;
Expand Down Expand Up @@ -64,8 +66,9 @@ class LagoonCommands extends DrushCommands implements SiteAliasManagerAwareInter
* {@inheritdoc}
*/
public function __construct() {
if (getenv('LAGOON')) {
// Get default config.
// Get default config.
if ($this->isLagoonEnvironment()) {
$this->isLagoonEnvironment = TRUE;
$lagoonyml = $this->getLagoonYml();
$this->api = $lagoonyml['api'] ?? 'https://api.lagoon.amazeeio.cloud/graphql';
$this->endpoint = $lagoonyml['ssh'] ?? 'ssh.lagoon.amazeeio.cloud:32222';
Expand All @@ -84,12 +87,10 @@ public function __construct() {

/**
* Get all remote aliases from lagoon API.
*
* @command lagoon:aliases
*
* @aliases la
*/
#[CLI\Command(name: 'lagoon:aliases', aliases: ['la'])]
public function aliases() {
$this->preCommandChecks();
// Project still not defined, throw a warning.
if ($this->projectName === FALSE) {
$this->logger()->warning('ERROR: Could not discover project name, you should define it inside your .lagoon.yml file');
Expand Down Expand Up @@ -121,30 +122,28 @@ public function aliases() {

/**
* Generate a JWT token for the lagoon API.
*
* @command lagoon:jwt
*
* @aliases jwt
*/
#[CLI\Command(name: 'lagoon:jwt', aliases: ['jwt'])]
public function generateJwt() {
$this->preCommandChecks();
$this->io()->writeln($this->getJwtToken());
}

/**
* Run pre-rollout tasks.
*
* @command lagoon:pre-rollout-tasks
*/
#[CLI\Command(name: 'lagoon:pre-rollout-tasks')]
public function preRolloutTasks() {
$this->preCommandChecks();
$this->runRolloutTasks('pre');
}

/**
* Run post-rollout tasks.
*
* @command lagoon:post-rollout-tasks
*/
#[CLI\Command(name: 'lagoon:post-rollout-tasks')]
public function postRolloutTasks() {
$this->preCommandChecks();
$this->runRolloutTasks('post');
}

Expand Down Expand Up @@ -264,4 +263,25 @@ public function getLagoonEnvs() {
return json_decode($response);
}

/**
* Will check whether the current environment is Lagoon or Lagoon dev envs.
*
* @return bool
* is a functional Lagoon env
*/
private function isLagoonEnvironment() {
return !empty(getenv("LAGOON"));
}

/**
* This should be run before any Lagoon commands.
*
* Checks whether we have a valid environment before running.
*/
private function preCommandChecks() {
if ($this->isLagoonEnvironment() == FALSE) {
throw new CommandFailedException(dt("Attempting to run a Lagoon command in a non-Lagoon environment."));
}
}

}