public function runWithTry(array $argv)
{
try {
return $this->run($argv);
} catch (CommandArgumentNotEnoughException $e) {
$this->logger->error($e->getMessage());
$this->logger->writeln('Expected argument prototypes:');
foreach ($e->getCommand()->getAllCommandPrototype() as $p) {
$this->logger->writeln("\t" . $p);
}
$this->logger->newline();
} catch (CommandNotFoundException $e) {
$this->logger->error($e->getMessage() . ' available commands are: ' . implode(', ', $e->getCommand()->getVisibleCommandList()));
$this->logger->newline();
$this->logger->writeln('Please try the command below to see the details:');
$this->logger->newline();
$this->logger->writeln("\t" . $this->getProgramName() . ' help ');
$this->logger->newline();
} catch (SystemCommandException $e) {
// Todo: detect $lastline for library missing here...
$buildLog = $e->getLogFile();
$this->logger->error('Error: ' . trim($e->getMessage()));
if (file_exists($buildLog)) {
$this->logger->error('The last 5 lines in the log file:');
$lines = array_slice(file($buildLog), -5);
foreach ($lines as $line) {
echo $line, PHP_EOL;
}
$this->logger->error('Please checkout the build log file for more details:');
$this->logger->error("\t tail {$buildLog}");
}
} catch (BadMethodCallException $e) {
$this->logger->error($e->getMessage());
$this->logger->error('Seems like an application logic error, please contact the developer.');
} catch (Exception $e) {
if ($this->options && $this->options->debug) {
$printer = new DevelopmentExceptionPrinter($this->getLogger());
$printer->dump($e);
} else {
$printer = new ProductionExceptionPrinter($this->getLogger());
$printer->dump($e);
}
}
return false;
}