Skip to content

Commit

Permalink
run -p/--print (v1.2.0)
Browse files Browse the repository at this point in the history
  • Loading branch information
beccasaurus committed May 12, 2021
1 parent 1a107d3 commit 912cd26
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -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 ;;
Expand All @@ -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
}
30 changes: 30 additions & 0 deletions spec/run.spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 912cd26

Please sign in to comment.