diff --git a/src/CliProgram/SafeApplication.php b/src/CliProgram/SafeApplication.php new file mode 100644 index 0000000..a7b9151 --- /dev/null +++ b/src/CliProgram/SafeApplication.php @@ -0,0 +1,75 @@ +processRuntimeException($exception, $input, $output); + } + } + + /** + * The exit code used when command failed with an exception + * + * @return int The exit code used when command failed with an exception + */ + public function getExceptionFailureExitCode (): int { + return $this->exceptionFailureExitCode; + } + /** + * Set the exit code used when command failed with an exception + * + * @param int $exceptionFailureExitCode The new exit code used when command failed with an exception + * + * @return $this + */ + public function setExceptionFailureExitCode (int $exceptionFailureExitCode): self { + $this->exceptionFailureExitCode = $exceptionFailureExitCode; + return $this; + } + /** + * Process runtime exception + * + * Default behavior: write exception message to $output (error) and return {@see SafeApplication::$exceptionFailureExitCode} + * + * @param Throwable $exception The exception + * @param InputInterface $input The input (i.e. argv) + * @param OutputInterface $output The output (i.e. STDOUT and STDERR) + * + * @return int The exit code + * + * @noinspection PhpUnusedParameterInspection + */ + protected function processRuntimeException (Throwable $exception, InputInterface $input, OutputInterface $output): int { + $output->writeln('' . $exception->getMessage() . ''); + return $this->exceptionFailureExitCode; + } +} \ No newline at end of file