diff --git a/README.md b/README.md index 4a32b62..dcaaeeb 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ --- -Download the [latest version](https://github.com/specs-sh/run.sh/archive/v1.1.0.tar.gz) or install via: +Download the [latest version](https://github.com/specs-sh/run.sh/archive/v1.2.0.tar.gz) or install via: ``` curl -o- https://run.specs.sh/install.sh | bash diff --git a/docs/_config.yml b/docs/_config.yml index 84c3e03..f9d318f 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -10,8 +10,8 @@ baseurl: "" # the subpath of your site, e.g. /blog url: "" # the base hostname & protocol for your site, e.g. http://example.com github: - zip_url: https://github.com/specs-sh/run.sh/archive/v1.1.0.zip - tar_url: https://github.com/specs-sh/run.sh/archive/v1.1.0.tar.gz + zip_url: https://github.com/specs-sh/run.sh/archive/v1.2.0.zip + tar_url: https://github.com/specs-sh/run.sh/archive/v1.2.0.tar.gz owner_url: https://github.com/beccasaurus owner_name: "@beccasaurus" diff --git a/docs/index.md b/docs/index.md index ecb3270..566d8b2 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,7 +15,7 @@ --- -Download the [latest version](https://github.com/specs-sh/run.sh/archive/v1.1.0.tar.gz) or install via: +Download the [latest version](https://github.com/specs-sh/run.sh/archive/v1.2.0.tar.gz) or install via: ``` curl -o- https://run.specs.sh/install.sh | bash diff --git a/run.sh b/run.sh index 3e5e869..89dd690 100644 --- a/run.sh +++ b/run.sh @@ -1,13 +1,13 @@ run() { STDOUT= STDERR= EXITCODE= + local -a __run__command=() + local __run__printResults= __run__blockOpen= __run__blockClose= __run__runInSubShell= __run__stdoutTempFile __run__stderrTempFile - local -r RUN_VERSION="1.1.0" + local -r RUN_VERSION="1.2.0" [ "${1:-}" = --version ] && { echo "run version $RUN_VERSION"; return 0; } + [ "${1:-}" = -p ] || [ "${1:-}" = --print ] && { __run__printResults=true; shift; } (( $# == 0 )) && return 0 - local -a __run__command=() - local __run__blockOpen= __run__blockClose= __run__runInSubShell= __run__stdoutTempFile __run__stderrTempFile - case "$1" in {) __run__blockOpen={; __run__blockClose=}; shift ;; [) __run__blockOpen=[; __run__blockClose=]; shift ;; @@ -34,5 +34,10 @@ run() { fi STDERR="$( < "$__run__stderrTempFile" )" || echo "run: failed to read standard error from temporary file '$__run__stderrTempFile' created using 'mktemp'" >&2 [ -f "$__run__stderrTempFile" ] && { rm "$__run__stderrTempFile" || echo "run: failed to delete temporary file used for standard error '$__run__stderrTempFile' created using 'mktemp'" >&2; } + + if [ "$__run__printResults" = true ]; then + printf "RUN: %s\nEXITCODE: %s\nSTDOUT: '%s'\nSTDERR: '%s'\n" "${__run__command[*]}" "$EXITCODE" "$STDOUT" "$STDERR" + fi + return $EXITCODE } \ No newline at end of file diff --git a/spec/run.spec.sh b/spec/run.spec.sh index bb79a56..11a2e8d 100644 --- a/spec/run.spec.sh +++ b/spec/run.spec.sh @@ -406,4 +406,34 @@ spec.curlies.or.brackets.with.extra.arguments() { [[ "$STDERR" = *"run: unexpected argument 'extra' after { ... }"* ]] refute run run [[ ls ]] hello world [[ "$STDERR" = *"run: unexpected arguments 'hello world' after [[ ... ]]"* ]] +} + +spec.can.print.run.info() { + assert run echo Hello + [[ "$STDOUT" != *"RUN: echo hello"* ]] + [[ "$STDOUT" != *"EXITCODE: 0"* ]] + [[ "$STDOUT" != *"STDOUT: 'Hello'"* ]] + [[ "$STDOUT" != *"STDERR: ''"* ]] + + assert run run -p echo Hello + [[ "$STDOUT" = *"RUN: echo Hello"* ]] + [[ "$STDOUT" = *"EXITCODE: 0"* ]] + [[ "$STDOUT" = *"STDOUT: 'Hello'"* ]] + [[ "$STDOUT" = *"STDERR: ''"* ]] + + assert run run --print echo "Hello, world!" + [[ "$STDOUT" = *"RUN: echo Hello, world!"* ]] + [[ "$STDOUT" = *"EXITCODE: 0"* ]] + [[ "$STDOUT" = *"STDOUT: 'Hello, world!'"* ]] + [[ "$STDOUT" = *"STDERR: ''"* ]] + + assert run run -p echoToStderr Hello + [[ "$STDOUT" = *"RUN: echoToStderr Hello"* ]] + [[ "$STDOUT" = *"EXITCODE: 0"* ]] + [[ "$STDOUT" = *"STDOUT: ''"* ]] + [[ "$STDOUT" = *"STDERR: 'Hello'"* ]] +} + +echoToStderr() { + echo "$@" >&2 } \ No newline at end of file