summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYvan Roux <yvan.roux@linaro.org>2016-01-27 13:49:30 +0100
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2016-05-16 12:22:37 +0000
commitc20c14668098dad728830fbfc5fe9c9446c3f782 (patch)
treed699099726b8ee44917b81e8a7c2e9b87fce417c
parent6d4f0f07751e949c67be26bf31ac3a622df1b2ff (diff)
Add verbose output option: -v.
Three levels of verbosity are provided from simple unexpanded commands to full set -x output. Change-Id: I04f14e15a138690468dba76f98f6e8cccd94c838
-rwxr-xr-xtcwg-release.sh28
1 files changed, 26 insertions, 2 deletions
diff --git a/tcwg-release.sh b/tcwg-release.sh
index 6fa7e9f..2b41a20 100755
--- a/tcwg-release.sh
+++ b/tcwg-release.sh
@@ -17,7 +17,7 @@ usage() {
cat << EOF
${release_script} [-a FILE] [-b BRANCH] [-d DATE] [-h] [-e REMOTE]
[-f FILESERVER] [-n] [-r [RC] [SPIN]] [-R [SPIN]] [-S [SPIN]]
- [-t TAG] [-u]
+ [-t TAG] [-u] [-v]
EOF
return 0
}
@@ -185,6 +185,10 @@ ${bold}OPTIONS${NC}"
and not use a TAG. Using -t with -b is not allowed since
-t and -b are both aliases for a single commit.
+ -v
+ Emit verbose output. Use more than once to increase output
+ further.
+
-u
EOF
echo -e "\
@@ -332,9 +336,15 @@ die() {
}
handle_ctrl_c() {
+ # set -x is not well handled by trap and cleanup, so turning it off.
+ (( VERBOSITY >= 2 )) && set +x
clean_and_die "User hit ctrl-c. Operation aborted."
}
+debug_handler() {
+ echo "$BASH_COMMAND" | grep -v "echo\|ask\|print\|exec\|eval\|\[\|\]"
+}
+
# arg1: a date in any format
# print a sanitized version of the date, or the error
# as generated by `date` if the input is invalid. The
@@ -542,6 +552,7 @@ hint() {
dirs -c
GIT_REPO="$PWD"
+VERBOSITY=0
# Leave these unset by default!
SPIN=
@@ -561,7 +572,7 @@ release_script="$(basename "$0")"
# Arguments. The first colon puts getopts into silent error reporting mode
# which sets $OPTARG to the unknown option if one is encountered.
-while getopts ":a:b:d:e:f:hnrRSt:u" options
+while getopts ":a:b:d:e:f:hnrRSt:uv" options
do
case $options in
a ) gitlog_amend="--amend $OPTARG"
@@ -613,6 +624,8 @@ do
;;
u ) extended_usage; exit 1;
;;
+ v ) (( VERBOSITY=VERBOSITY+1 ))
+ ;;
\?) print_info "Option -${BOLD}$OPTARG${NC} Unsupported."
;;
: ) extended_usage; die "Option \"-$OPTARG\" requires an argument."
@@ -672,6 +685,17 @@ if [[ "${TAG:+t}" = "t" && "${BRANCH:+b}" = "b" ]]; then
die "Using -t and -b together is not allowed."
fi
+# Handle verbosity mode
+if (( VERBOSITY == 1 )); then
+ trap "debug_handler" DEBUG;
+elif (( VERBOSITY == 2 )); then
+ exec 4> >( grep -v "^++\|echo\|ask\|print\|exec\|eval\|\[\|\]" >&2)
+ BASH_XTRACEFD=4
+ set -x;
+elif (( VERBOSITY >= 3 )); then
+ set -x;
+fi
+
# Track either the BRANCH or the TAG
track="${BRANCH:+${BRANCH}}${TAG:+${TAG}}"