/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int * @throws \Exception */ public function run(InputInterface $input = NULL, OutputInterface $output = NULL) { $input = $input ?: new ArgvInput(); $output = $output ?: new ConsoleOutput(); if ($input->hasParameterOption('--debug-mode')) { if ($input->hasParameterOption(['--debug-mode=no', '--debug-mode=off', '--debug-mode=false', '--debug-mode=0'])) { if ($this->serviceLocator->parameters['debugMode']) { $this->renderException(new InvalidApplicationModeException("The app is running in debug mode. You have to use Kdyby\\Console\\DI\\BootstrapHelper in app/bootstrap.php, " . "Kdyby\\Console cannot switch already running app to production mode . "), $output); return self::INVALID_APP_MODE_EXIT_CODE; } } else { if (!$this->serviceLocator->parameters['debugMode']) { $this->renderException(new InvalidApplicationModeException("The app is running in production mode. You have to use Kdyby\\Console\\DI\\BootstrapHelper in app/bootstrap.php, " . "Kdyby\\Console cannot switch already running app to debug mode."), $output); return self::INVALID_APP_MODE_EXIT_CODE; } } } if (class_exists('Tracy\\Dumper') && $input->hasParameterOption('--no-ansi')) { Dumper::$terminalColors = FALSE; } try { return parent::run($input, $output); } catch (UnknownCommandException $e) { $this->renderException($e->getPrevious(), $output); list($message) = explode("\n", $e->getMessage()); Debugger::log($message, Debugger::ERROR); return self::INPUT_ERROR_EXIT_CODE; } catch (\Exception $e) { if (in_array(get_class($e), self::$invalidArgumentExceptions, TRUE) && preg_match('/^(The "-?-?.+" (option|argument) (does not (exist|accept a value)|requires a value)|(Not enough|Too many) arguments.*)\\.$/', $e->getMessage()) === 1) { $this->renderException($e, $output); Debugger::log($e->getMessage(), Debugger::ERROR); return self::INPUT_ERROR_EXIT_CODE; } elseif ($app = $this->serviceLocator->getByType('Nette\\Application\\Application', FALSE)) { /** @var Nette\Application\Application $app */ $app->onError($app, $e); } else { $this->handleException($e, $output); } return max(min((int) $e->getCode(), 254), 1); } }