Skip to content

Commit

Permalink
Merge pull request #9 from mikaellanger/shell-exit-codes
Browse files Browse the repository at this point in the history
Exit with code 1 on failure
  • Loading branch information
byjg authored Apr 21, 2021
2 parents 2b4b05c + de82c94 commit 8c748a7
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/ConsoleCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('Doing: ' . $command . " to " . $version);
});
}
return 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('Created UP version: ' . $this->createMigrationSql("$path/migrations/up", 0));
$output->writeln('Created DOWN version: ' . $this->createMigrationSql("$path/migrations/down", -1));
}
return 0;
}
}
11 changes: 7 additions & 4 deletions src/DatabaseVersionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ protected function configure()

protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
try {
$versionInfo = $this->migration->getCurrentVersion();
$output->writeln('version: ' . $versionInfo['version']);
$output->writeln('status.: ' . $versionInfo['status']);
if (parent::execute($input, $output) == 0) {
$versionInfo = $this->migration->getCurrentVersion();
$output->writeln('version: ' . $versionInfo['version']);
$output->writeln('status.: ' . $versionInfo['status']);
return 0;
}
} catch (Exception $ex) {
$this->handleError($ex, $output);
}
return 1;
}
}
9 changes: 6 additions & 3 deletions src/DownCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborted.');

return;
return 1;
}
}

parent::execute($input, $output);
$this->migration->down($this->upTo, true);
if (parent::execute($input, $output) == 0) {
$this->migration->down($this->upTo, true);
return 0;
}
} catch (Exception $ex) {
$this->handleError($ex, $output);
}
return 1;
}
}
6 changes: 5 additions & 1 deletion src/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
parent::execute($input, $output);
if (parent::execute($input, $output) != 0) {
return 1;
};

$action = 'Database is already versioned. ';
try {
Expand All @@ -44,8 +46,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln($action);
$output->writeln('current version: ' . $version['version']);
$output->writeln('current status.: ' . $version['status']);
return 0;
} catch (Exception $ex) {
$this->handleError($ex, $output);
return 1;
}
}
}
11 changes: 7 additions & 4 deletions src/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborted.');

return;
return 1;
}
}

parent::execute($input, $output);
$this->migration->prepareEnvironment();
$this->migration->reset($this->upTo);
if (parent::execute($input, $output) == 0) {
$this->migration->prepareEnvironment();
$this->migration->reset($this->upTo);
return 0;
}
} catch (Exception $ex) {
$this->handleError($ex, $output);
}
return 1;
}
}
9 changes: 6 additions & 3 deletions src/UpdateCommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$helper->ask($input, $output, $question)) {
$output->writeln('Aborted.');

return;
return 1;
}
}

parent::execute($input, $output);
$this->callMigrate();
if (parent::execute($input, $output) == 0) {
$this->callMigrate();
return 0;
}
} catch (Exception $ex) {
$this->handleError($ex, $output);
}
return 1;
}
}

0 comments on commit 8c748a7

Please sign in to comment.