/** * Execute `run` method with a default try & catch block to catch the exception. * * @param array $argv * * @return bool return true for success, false for failure. the returned * state will be reflected to the exit code of the process. */ 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: " . join(', ', $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 (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; }