Skip to content

Commit

Permalink
Merge pull request #143 from owncloud/occ_exit_codes
Browse files Browse the repository at this point in the history
provide non-zero exit codes on failure
  • Loading branch information
Vincent Petry authored Sep 6, 2017
2 parents e0f9bd2 + 16785d7 commit 6e189cd
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
11 changes: 9 additions & 2 deletions lib/Command/InstallApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class InstallApp extends Command {
/** @var MarketService */
private $marketService;

/** @var int */
private $exitCode = 0;

public function __construct(MarketService $marketService) {
parent::__construct();
$this->marketService = $marketService;
Expand Down Expand Up @@ -89,7 +92,8 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("$appId: App installed.");
}
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
$output->writeln("<error> $appId: {$ex->getMessage()} </error>");
$this->exitCode = 1;
}
}
} else {
Expand All @@ -110,9 +114,12 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("$appId: App installed.");
}
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
$output->writeln("<error> $appId: {$ex->getMessage()} </error>");
$this->exitCode = 1;
}
}
}

return $this->exitCode;
}
}
7 changes: 6 additions & 1 deletion lib/Command/ListApps.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ protected function configure() {
}

protected function execute(InputInterface $input, OutputInterface $output) {
$apps = $this->marketService->listApps();
try {
$apps = $this->marketService->listApps();
} catch (\Exception $ex) {
$output->writeln("<error>{$ex->getMessage()} </error>");
return 1;
}

usort($apps, function ($a, $b) {
return strcmp($a['id'], $b['id']);
Expand Down
7 changes: 6 additions & 1 deletion lib/Command/UnInstallApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class UnInstallApp extends Command {
/** @var MarketService */
private $marketService;

/** @var int */
private $exitCode = 0;

public function __construct(MarketService $marketService) {
parent::__construct();
$this->marketService = $marketService;
Expand Down Expand Up @@ -67,8 +70,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$this->marketService->uninstallApp($appId);
$output->writeln("$appId: App uninstalled.");
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
$output->writeln("<error>$appId: {$ex->getMessage()}</error>");
$this->exitCode = 1;
}
}
return $this->exitCode;
}
}
12 changes: 9 additions & 3 deletions lib/Command/UpgradeApp.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class UpgradeApp extends Command {
/** @var MarketService */
private $marketService;

/** @var int */
private $exitCode = 0;

public function __construct(MarketService $marketService) {
parent::__construct();
$this->marketService = $marketService;
Expand Down Expand Up @@ -80,10 +83,11 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("$appId: Not installed ...");
}
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
$output->writeln("<error>$appId: {$ex->getMessage()}</error>");
$this->exitCode = 1;
}
}
return;
return $this->exitCode;
}

if ($input->getOption('list')) {
Expand Down Expand Up @@ -116,8 +120,10 @@ protected function execute(InputInterface $input, OutputInterface $output) {
$output->writeln("$appId: Not installed ...");
}
} catch (\Exception $ex) {
$output->writeln("$appId: {$ex->getMessage()}");
$output->writeln("<error>$appId: {$ex->getMessage()}</error>");
$this->exitCode = 1;
}
}
return $this->exitCode;
}
}

0 comments on commit 6e189cd

Please sign in to comment.