diff --git a/src/Commands/CodeCommand.php b/src/Commands/CodeCommand.php index 685f39b..4d5ff43 100644 --- a/src/Commands/CodeCommand.php +++ b/src/Commands/CodeCommand.php @@ -3,6 +3,7 @@ namespace AcquiaCli\Commands; use AcquiaCloudApi\Response\BranchResponse; +use AcquiaCloudApi\Response\EnvironmentResponse; use Symfony\Component\Console\Helper\Table; use AcquiaCloudApi\Endpoints\Code; @@ -20,6 +21,7 @@ class CodeCommand extends AcquiaCommand * @param string $match A string to filter out specific code branches with. * * @command code:list + * @aliases c:l */ public function code($uuid, $match = null) { @@ -48,4 +50,74 @@ public function code($uuid, $match = null) $table->render(); } + + /** + * Deploys code from one environment to another. + * + * @param string $uuid + * @param EnvironmentResponse $environmentFrom + * @param EnvironmentResponse $environmentTo + * + * @command code:deploy + * @aliases c:d + */ + public function codeDeploy( + $uuid, + EnvironmentResponse $environmentFrom, + EnvironmentResponse $environmentTo + ) { + if (!$this->confirm( + sprintf( + 'Are you sure you want to deploy code from %s to %s?', + $environmentFrom->label, + $environmentTo->label + ) + )) { + return; + } + + $this->backupAllEnvironmentDbs($uuid, $environmentTo); + + $this->say( + sprintf( + 'Deploying code from the %s environment to the %s environment', + $environmentFrom->label, + $environmentTo->label + ) + ); + + $code = new Code($this->cloudapi); + $response = $code->deploy($environmentFrom->uuid, $environmentTo->uuid); + $this->waitForNotification($response); + } + + /** + * Switches code branch on an environment. + * + * @param string $uuid + * @param EnvironmentResponse $environment + * @param string $branch + * + * @command code:switch + * @aliases c:s + */ + public function codeSwitch($uuid, EnvironmentResponse $environment, $branch) + { + if (!$this->confirm( + sprintf( + 'Are you sure you want to switch code on the %s environment to branch: %s?', + $environment->name, + $branch + ) + )) { + return; + } + + $this->backupAllEnvironmentDbs($uuid, $environment); + + $this->say(sprintf('Switching %s enviroment to %s branch', $environment->label, $branch)); + $code = new Code($this->cloudapi); + $response = $code->switch($environment->uuid, $branch); + $this->waitForNotification($response); + } }