diff --git a/DOCS.md b/DOCS.md index 7661649..72657ef 100644 --- a/DOCS.md +++ b/DOCS.md @@ -781,6 +781,8 @@ class ExecOutput { public const OPT_CMD = 'cmd'; /** The format to output the result in - options include "raw" "code" and "code-block" defaults to "raw" */ public const OPT_FORMAT = 'format'; + /** Set to 'true' to allow non-zero exit codes to continue */ + public const OPT_ALLOW_ERROR = 'allow-error'; public const FORMAT_DEFAULT = 'default'; public const FORMAT_RAW = 'raw'; public const FORMAT_CODE = 'code'; diff --git a/README.md b/README.md index a5a3be5..a6b7f23 100644 --- a/README.md +++ b/README.md @@ -352,4 +352,5 @@ Execute a command and include the standard output in the documentation #### Attributes: - `cmd` **(required)** - The command to execute -- `format` - The format to output the result in - options include "raw" "code" and "code-block" defaults to "raw" \ No newline at end of file +- `format` - The format to output the result in - options include "raw" "code" and "code-block" defaults to "raw" +- `allow-error` - Set to 'true' to allow non-zero exit codes to continue \ No newline at end of file diff --git a/src/Documentation/ExecOutput.php b/src/Documentation/ExecOutput.php index 1d8af21..fe0451e 100644 --- a/src/Documentation/ExecOutput.php +++ b/src/Documentation/ExecOutput.php @@ -22,6 +22,8 @@ class ExecOutput extends AbstractDocPart { public const OPT_CMD = 'cmd'; /** The format to output the result in - options include "raw" "code" and "code-block" defaults to "raw" */ public const OPT_FORMAT = 'format'; + /** Set to 'true' to allow non-zero exit codes to continue */ + public const OPT_ALLOW_ERROR = 'allow-error'; public const FORMAT_DEFAULT = 'default'; public const FORMAT_RAW = 'raw'; @@ -42,6 +44,7 @@ class ExecOutput extends AbstractDocPart { public function output( int $depth ) : AbstractElement { $cmd = $this->getOption(self::OPT_CMD); $format = $this->getOption(self::OPT_FORMAT); + $allow = $this->getOption(self::OPT_ALLOW_ERROR); if( !in_array($format, self::FORMATS, true) ) { throw new ConfigException("Invalid exec format '{$format}', expected to be in: " . implode(', ', self::FORMATS)); @@ -49,7 +52,7 @@ public function output( int $depth ) : AbstractElement { exec($cmd, $output, $return); - if( $return !== 0 ) { + if( !$allow && $return !== 0 ) { throw new ExecutionException("Command `{$cmd}` returned exit code: {$return}", $return); }