mirror of
https://github.com/hauke68/Magallanes.git
synced 2025-08-25 21:00:18 +02:00
Proper exit code. Issue #52
This commit is contained in:
parent
8df5534470
commit
5d728a9105
@ -28,6 +28,7 @@ abstract class AbstractCommand
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the Command
|
* Runs the Command
|
||||||
|
* @return integer exit code
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public abstract function run();
|
public abstract function run();
|
||||||
|
@ -28,12 +28,14 @@ class CompileCommand extends AbstractCommand
|
|||||||
{
|
{
|
||||||
if (ini_get('phar.readonly')) {
|
if (ini_get('phar.readonly')) {
|
||||||
Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);
|
Console::output('The <purple>php.ini</purple> variable <light_red>phar.readonly</light_red> must be <yellow>Off</yellow>.', 1, 2);
|
||||||
return;
|
return 300;
|
||||||
}
|
}
|
||||||
|
|
||||||
$compiler = new Compiler;
|
$compiler = new Compiler;
|
||||||
$compiler->compile();
|
$compiler->compile();
|
||||||
|
|
||||||
Console::output('<light_purple>mage.phar</light_purple> compiled <light_green>successfully</light_green>', 0, 2);
|
Console::output('<light_purple>mage.phar</light_purple> compiled <light_green>successfully</light_green>', 0, 2);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,18 +108,20 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 1000;
|
||||||
|
|
||||||
// Check if Environment is not Locked
|
// Check if Environment is not Locked
|
||||||
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
||||||
if (file_exists($lockFile)) {
|
if (file_exists($lockFile)) {
|
||||||
Console::output('<red>This environment is locked!</red>', 1, 2);
|
Console::output('<red>This environment is locked!</red>', 1, 2);
|
||||||
echo file_get_contents($lockFile);
|
echo file_get_contents($lockFile);
|
||||||
return;
|
return 1010;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for running instance and Lock
|
// Check for running instance and Lock
|
||||||
if (file_exists(getcwd() . '/.mage/~working.lock')) {
|
if (file_exists(getcwd() . '/.mage/~working.lock')) {
|
||||||
Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
|
Console::output('<red>There is already an instance of Magallanes running!</red>', 1, 2);
|
||||||
return;
|
return 1020;
|
||||||
} else {
|
} else {
|
||||||
touch(getcwd() . '/.mage/~working.lock');
|
touch(getcwd() . '/.mage/~working.lock');
|
||||||
}
|
}
|
||||||
@ -193,6 +195,12 @@ class DeployCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
if (file_exists(getcwd() . '/.mage/~working.lock')) {
|
if (file_exists(getcwd() . '/.mage/~working.lock')) {
|
||||||
unlink(getcwd() . '/.mage/~working.lock');
|
unlink(getcwd() . '/.mage/~working.lock');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self::$failedTasks === 0) {
|
||||||
|
$exitCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ class InitCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 50;
|
||||||
$configDir = getcwd() . '/.mage';
|
$configDir = getcwd() . '/.mage';
|
||||||
|
|
||||||
Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
|
Console::output('Initiating managing process for application with <dark_gray>Magallanes</dark_gray>');
|
||||||
@ -49,9 +50,13 @@ class InitCommand extends AbstractCommand
|
|||||||
if (!in_array(false, $results)) {
|
if (!in_array(false, $results)) {
|
||||||
Console::output('<light_green>Success!!</light_green> The configuration for <dark_gray>Magallanes</dark_gray> has been generated at <blue>.mage</blue> directory.');
|
Console::output('<light_green>Success!!</light_green> The configuration for <dark_gray>Magallanes</dark_gray> has been generated at <blue>.mage</blue> directory.');
|
||||||
Console::output('<dark_gray>Please!! Review and adjust the configuration.</dark_gray>', 2, 2);
|
Console::output('<dark_gray>Please!! Review and adjust the configuration.</dark_gray>', 2, 2);
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Console::output('<light_red>Error!!</light_red> Unable to generate the configuration.', 1, 2);
|
Console::output('<light_red>Error!!</light_red> Unable to generate the configuration.', 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ class InstallCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 88;
|
||||||
Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
Console::output('Installing <dark_gray>Magallanes</dark_gray>... ', 1, 0);
|
||||||
|
|
||||||
// Vars
|
// Vars
|
||||||
@ -74,7 +75,10 @@ class InstallCommand extends AbstractCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
Console::output('<light_green>Success!</light_green>', 0, 2);
|
Console::output('<light_green>Success!</light_green>', 0, 2);
|
||||||
|
$exitCode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,12 +31,13 @@ class ListCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 600;
|
||||||
$subCommand = $this->getConfig()->getArgument(1);
|
$subCommand = $this->getConfig()->getArgument(1);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch ($subCommand) {
|
switch ($subCommand) {
|
||||||
case 'environments':
|
case 'environments':
|
||||||
$this->listEnvironments();
|
$exitCode = $this->listEnvironments();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default;
|
default;
|
||||||
@ -46,6 +47,8 @@ class ListCommand extends AbstractCommand
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Console::output('<red>' . $e->getMessage() . '</red>', 1, 2);
|
Console::output('<red>' . $e->getMessage() . '</red>', 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,6 +56,7 @@ class ListCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
protected function listEnvironments()
|
protected function listEnvironments()
|
||||||
{
|
{
|
||||||
|
$exitCode = 600;
|
||||||
$environments = array();
|
$environments = array();
|
||||||
$content = scandir(getcwd() . '/.mage/config/environment/');
|
$content = scandir(getcwd() . '/.mage/config/environment/');
|
||||||
foreach ($content as $file) {
|
foreach ($content as $file) {
|
||||||
@ -68,9 +72,12 @@ class ListCommand extends AbstractCommand
|
|||||||
Console::output('* <light_red>' . $environment . '</light_red>', 2, 1);
|
Console::output('* <light_red>' . $environment . '</light_red>', 2, 1);
|
||||||
}
|
}
|
||||||
Console::output('', 1, 1);
|
Console::output('', 1, 1);
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2);
|
Console::output('<dark_gray>You don\'t have any environment configured.</dark_gray>', 1, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,6 +43,8 @@ class LockCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
file_put_contents($lockFile, 'Locked environment at date: ' . date('Y-m-d H:i:s') . $lockmsg);
|
file_put_contents($lockFile, 'Locked environment at date: ' . date('Y-m-d H:i:s') . $lockmsg);
|
||||||
|
|
||||||
Console::output('Locked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2);
|
Console::output('Locked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$result = false;
|
$exitCode = 400;
|
||||||
$subCommand = $this->getConfig()->getArgument(1);
|
$subCommand = $this->getConfig()->getArgument(1);
|
||||||
|
|
||||||
// Run Tasks for Deployment
|
// Run Tasks for Deployment
|
||||||
@ -40,9 +40,10 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
1, 3
|
1, 3
|
||||||
);
|
);
|
||||||
|
|
||||||
return false;
|
return 401;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = true;
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
$this->getConfig()->setHost($host);
|
$this->getConfig()->setHost($host);
|
||||||
|
|
||||||
@ -50,14 +51,14 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
case 'list':
|
case 'list':
|
||||||
$task = Factory::get('releases/list', $this->getConfig());
|
$task = Factory::get('releases/list', $this->getConfig());
|
||||||
$task->init();
|
$task->init();
|
||||||
$result = $task->run();
|
$result = $task->run() && $result;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'rollback':
|
case 'rollback':
|
||||||
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
|
if (!is_numeric($this->getConfig()->getParameter('release', ''))) {
|
||||||
Console::output('<red>Missing required releaseid.</red>', 1, 2);
|
Console::output('<red>Missing required releaseid.</red>', 1, 2);
|
||||||
|
|
||||||
return false;
|
return 410;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
||||||
@ -65,18 +66,22 @@ class ReleasesCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
Console::output('<red>This environment is locked!</red>', 1, 2);
|
Console::output('<red>This environment is locked!</red>', 1, 2);
|
||||||
echo file_get_contents($lockFile);
|
echo file_get_contents($lockFile);
|
||||||
|
|
||||||
return false;
|
return 420;
|
||||||
}
|
}
|
||||||
|
|
||||||
$releaseId = $this->getConfig()->getParameter('release', '');
|
$releaseId = $this->getConfig()->getParameter('release', '');
|
||||||
$this->getConfig()->setReleaseId($releaseId);
|
$this->getConfig()->setReleaseId($releaseId);
|
||||||
$task = Factory::get('releases/rollback', $this->getConfig());
|
$task = Factory::get('releases/rollback', $this->getConfig());
|
||||||
$task->init();
|
$task->init();
|
||||||
$result = $task->run();
|
$result = $task->run() && $result;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
if ($result) {
|
||||||
|
$exitCode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,19 +28,19 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$result = false;
|
$exitCode = 450;
|
||||||
$releaseId = $this->getConfig()->getArgument(1);
|
$releaseId = $this->getConfig()->getArgument(1);
|
||||||
|
|
||||||
if (!is_numeric($releaseId)) {
|
if (!is_numeric($releaseId)) {
|
||||||
Console::output('<red>This release is mandatory.</red>', 1, 2);
|
Console::output('<red>This release is mandatory.</red>', 1, 2);
|
||||||
return false;
|
return 451;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
$lockFile = getcwd() . '/.mage/' . $this->getConfig()->getEnvironment() . '.lock';
|
||||||
if (file_exists($lockFile)) {
|
if (file_exists($lockFile)) {
|
||||||
Console::output('<red>This environment is locked!</red>', 1, 2);
|
Console::output('<red>This environment is locked!</red>', 1, 2);
|
||||||
echo file_get_contents($lockFile);
|
echo file_get_contents($lockFile);
|
||||||
return null;
|
return 20;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run Tasks for Deployment
|
// Run Tasks for Deployment
|
||||||
@ -50,16 +50,21 @@ class RollbackCommand extends AbstractCommand implements RequiresEnvironment
|
|||||||
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
|
Console::output('<light_purple>Warning!</light_purple> <dark_gray>No hosts defined, unable to get releases.</dark_gray>', 1, 3);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
$result = true;
|
||||||
foreach ($hosts as $host) {
|
foreach ($hosts as $host) {
|
||||||
$this->getConfig()->setHost($host);
|
$this->getConfig()->setHost($host);
|
||||||
|
|
||||||
$this->getConfig()->setReleaseId($releaseId);
|
$this->getConfig()->setReleaseId($releaseId);
|
||||||
$task = Factory::get('releases/rollback', $this->getConfig());
|
$task = Factory::get('releases/rollback', $this->getConfig());
|
||||||
$task->init();
|
$task->init();
|
||||||
$result = $task->run();
|
$result = $task->run() && $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($result) {
|
||||||
|
$exitCode = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,8 @@ class UnlockCommand
|
|||||||
}
|
}
|
||||||
|
|
||||||
Console::output('Unlocked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2);
|
Console::output('Unlocked deployment to <light_purple>' . $this->getConfig()->getEnvironment() . '</light_purple> environment', 1, 2);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ class UpdateCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 200;
|
||||||
|
|
||||||
$task = Factory::get('scm/update', $this->getConfig());
|
$task = Factory::get('scm/update', $this->getConfig());
|
||||||
$task->init();
|
$task->init();
|
||||||
|
|
||||||
@ -35,9 +37,13 @@ class UpdateCommand extends AbstractCommand
|
|||||||
|
|
||||||
if ($result == true) {
|
if ($result == true) {
|
||||||
Console::output('<green>OK</green>' . PHP_EOL, 0);
|
Console::output('<green>OK</green>' . PHP_EOL, 0);
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Console::output('<red>FAIL</red>' . PHP_EOL, 0);
|
Console::output('<red>FAIL</red>' . PHP_EOL, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -38,6 +38,7 @@ class UpgradeCommand extends AbstractCommand
|
|||||||
*/
|
*/
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
|
$exitCode = 100;
|
||||||
Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0);
|
Console::output('Upgrading <dark_gray>Magallanes</dark_gray> ... ', 1, 0);
|
||||||
|
|
||||||
$user = '';
|
$user = '';
|
||||||
@ -59,10 +60,12 @@ class UpgradeCommand extends AbstractCommand
|
|||||||
if ($versionCompare == 0) {
|
if ($versionCompare == 0) {
|
||||||
Console::output('<yellow>SKIP</yellow>', 0, 1);
|
Console::output('<yellow>SKIP</yellow>', 0, 1);
|
||||||
Console::output('Your current version is up to date.', 2);
|
Console::output('Your current version is up to date.', 2);
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
} else if ($versionCompare == 1) {
|
} else if ($versionCompare == 1) {
|
||||||
Console::output('<yellow>SKIP</yellow>', 0, 1);
|
Console::output('<yellow>SKIP</yellow>', 0, 1);
|
||||||
Console::output('Your current version is newer.', 2);
|
Console::output('Your current version is newer.', 2);
|
||||||
|
$exitCode = 0;
|
||||||
|
|
||||||
} else if ($versionCompare == -1) {
|
} else if ($versionCompare == -1) {
|
||||||
// Download Package
|
// Download Package
|
||||||
@ -82,6 +85,7 @@ class UpgradeCommand extends AbstractCommand
|
|||||||
Console::executeCommand('mv ' . dirname($tarballFile) . '/magallanes ' . MAGALLANES_DIRECTORY);
|
Console::executeCommand('mv ' . dirname($tarballFile) . '/magallanes ' . MAGALLANES_DIRECTORY);
|
||||||
|
|
||||||
Console::output('<green>OK</green>', 0, 1);
|
Console::output('<green>OK</green>', 0, 1);
|
||||||
|
$exitCode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -93,5 +97,7 @@ class UpgradeCommand extends AbstractCommand
|
|||||||
Console::output('Invalid version.', 2);
|
Console::output('Invalid version.', 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $exitCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,8 @@ class VersionCommand extends AbstractCommand
|
|||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION . '</dark_gray>', 0, 2);
|
Console::output('Running <blue>Magallanes</blue> version <dark_gray>' . MAGALLANES_VERSION . '</dark_gray>', 0, 2);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -135,8 +135,7 @@ class Console
|
|||||||
throw new Exception('You must specify an environment for this command.');
|
throw new Exception('You must specify an environment for this command.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$command->run();
|
$exitCode = $command->run();
|
||||||
$exitCode = 0;
|
|
||||||
|
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
self::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
|
self::output('<red>' . $exception->getMessage() . '</red>', 1, 2);
|
||||||
|
Loading…
Reference in New Issue
Block a user