[vuln] devtools: add lib.sh

0 views
Skip to first unread message

Jonathan Amsterdam (Gerrit)

unread,
Dec 7, 2021, 12:14:07 PM12/7/21
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Julie Qiu, Gopher Robot, kokoro, Roland Shoemaker, golang-co...@googlegroups.com

Jonathan Amsterdam submitted this change.

View Change


Approvals: Julie Qiu: Looks good to me, approved Jonathan Amsterdam: Trusted; Run TryBots Objections: Gopher Robot: TryBots failed
devtools: add lib.sh

Move common shell functions to a separate file in anticipation
of more shell scripts.

Change-Id: Idf6148809f9498f4656cb8c28618ec2881deb5f7
Reviewed-on: https://go-review.googlesource.com/c/vuln/+/369835
Trust: Jonathan Amsterdam <j...@google.com>
Run-TryBot: Jonathan Amsterdam <j...@google.com>
Reviewed-by: Julie Qiu <ju...@golang.org>
---
A devtools/lib.sh
M all.bash
2 files changed, 59 insertions(+), 36 deletions(-)

diff --git a/all.bash b/all.bash
index 32961f7..0a46ce8 100755
--- a/all.bash
+++ b/all.bash
@@ -3,42 +3,7 @@
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

-RED=; GREEN=; YELLOW=; NORMAL=;
-MAXWIDTH=0
-
-if tput setaf 1 >& /dev/null; then
- RED=`tput setaf 1`
- GREEN=`tput setaf 2`
- YELLOW=`tput setaf 3`
- NORMAL=`tput sgr0`
- MAXWIDTH=$(( $(tput cols) - 2 ))
-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 '$ '.
- if [[ $MAXWIDTH -gt 0 && ${#msg} -gt $MAXWIDTH ]]; then
- msg="${msg::$(( MAXWIDTH - 3 ))}..."
- fi
-
- echo -e "$@\n" 1>&2;
- $@ || err "command failed"
-}
+source devtools/lib.sh

# ensure_go_binary verifies that a binary exists in $PATH corresponding to the
# given go-gettable URI. If no such binary exists, it is fetched via `go get`.
diff --git a/devtools/lib.sh b/devtools/lib.sh
new file mode 100644
index 0000000..94dccbb
--- /dev/null
+++ b/devtools/lib.sh
@@ -0,0 +1,42 @@
+# Copyright 2021 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.
+
+RED=; GREEN=; YELLOW=; NORMAL=;
+MAXWIDTH=0
+
+if tput setaf 1 >& /dev/null; then
+ RED=`tput setaf 1`
+ GREEN=`tput setaf 2`
+ YELLOW=`tput setaf 3`
+ NORMAL=`tput sgr0`
+ MAXWIDTH=$(( $(tput cols) - 2 ))
+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 '$ '.
+ if [[ $MAXWIDTH -gt 0 && ${#msg} -gt $MAXWIDTH ]]; then
+ msg="${msg::$(( MAXWIDTH - 3 ))}..."
+ fi
+
+ echo -e "$@\n" 1>&2;
+ $@ || err "command failed"
+}

To view, visit change 369835. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vuln
Gerrit-Branch: master
Gerrit-Change-Id: Idf6148809f9498f4656cb8c28618ec2881deb5f7
Gerrit-Change-Number: 369835
Gerrit-PatchSet: 2
Gerrit-Owner: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: Gopher Robot <go...@golang.org>
Gerrit-Reviewer: Jonathan Amsterdam <j...@google.com>
Gerrit-Reviewer: Julie Qiu <ju...@golang.org>
Gerrit-Reviewer: Roland Shoemaker <rol...@golang.org>
Gerrit-CC: kokoro <noreply...@google.com>
Gerrit-MessageType: merged
Reply all
Reply to author
Forward
0 new messages