зеркало из https://github.com/golang/pkgsite.git
all: modify all.bash to use scripts/lib.sh
Terminal colors for log levels and the runcmd helper function is added to scripts/lib.sh. all.bash now these functions. Updates b/151162757 Change-Id: Ic0ce1c89214bfa8704571647ead784d2b7ee37fb Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/687549 CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com> Reviewed-by: Jonathan Amsterdam <jba@google.com>
This commit is contained in:
Родитель
b0f1a8f66c
Коммит
56be005a3a
2
all.bash
2
all.bash
|
@ -3,7 +3,7 @@
|
|||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
source devtools/lib.sh || { echo "Are you at repo root?"; exit 1; }
|
||||
source scripts/lib.sh || { echo "Are you at repo root?"; exit 1; }
|
||||
|
||||
warnout() {
|
||||
while read line; do
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
# Copyright 2019 The Go Authors. All rights reserved.
|
||||
# Use of this source code is governed by a BSD-style
|
||||
# license that can be found in the LICENSE file.
|
||||
|
||||
# Library of useful bash functions and variables.
|
||||
|
||||
if [ -t 1 ] && which tput >/dev/null 2>&1; then
|
||||
RED="$(tput setaf 1)"
|
||||
GREEN="$(tput setaf 2)"
|
||||
YELLOW="$(tput setaf 3)"
|
||||
NORMAL="$(tput sgr0)"
|
||||
else
|
||||
RED=""
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
NORMAL=""
|
||||
fi
|
||||
|
||||
EXIT_CODE=0
|
||||
|
||||
info() { echo -e "${GREEN}$@${NORMAL}" 1>&2; }
|
||||
warn() { echo -e "${YELLOW}$@${NORMAL}" 1>&2; }
|
||||
err() { echo -e "${RED}$@${NORMAL}" 1>&2; EXIT_CODE=1; }
|
||||
|
||||
die() {
|
||||
err $@
|
||||
exit 1
|
||||
}
|
||||
|
||||
# runcmd prints an info log describing the command that is about to be run, and
|
||||
# then runs it. It sets EXIT_CODE to non-zero if the command fails, but does not exit
|
||||
# the script.
|
||||
runcmd() {
|
||||
msg="$@"
|
||||
# Truncate command logging for narrow terminals.
|
||||
# Account for the 2 characters of '$ '.
|
||||
maxwidth=$(( $(tput cols) - 2 ))
|
||||
if [[ ${#msg} -gt $maxwidth ]]; then
|
||||
msg="${msg::$(( maxwidth - 3 ))}..."
|
||||
fi
|
||||
info "\$ $msg"
|
||||
$@ || err "command failed"
|
||||
}
|
Загрузка…
Ссылка в новой задаче