From 74cd9cb1a795e22f7943d5455c45aacb93177354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Wed, 1 Nov 2017 09:16:37 +0200 Subject: [PATCH] Exit with 0 and output usage to stdout with --help --- wait-for-it.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/wait-for-it.sh b/wait-for-it.sh index 071c2be..3dec04a 100755 --- a/wait-for-it.sh +++ b/wait-for-it.sh @@ -7,7 +7,8 @@ echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } usage() { - cat << USAGE >&2 + [[ $1 ]] && out=2 || out=1 + cat << USAGE >&$out Usage: $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args] -h HOST | --host=HOST Host or IP under test @@ -19,7 +20,7 @@ Usage: Timeout in seconds, zero for no timeout -- COMMAND ARGS Execute command with args after the test finishes USAGE - exit 1 + exit ${1:-0} } wait_for() @@ -126,14 +127,14 @@ do ;; *) echoerr "Unknown argument: $1" - usage + usage 1 ;; esac done if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then echoerr "Error: you need to provide a host and port to test." - usage + usage 1 fi WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15}