golang: Add more error handling for go-gcc-helper
authorJeffery To <jeffery.to@gmail.com>
Fri, 28 Aug 2020 08:45:02 +0000 (16:45 +0800)
committerJeffery To <jeffery.to@gmail.com>
Tue, 6 Oct 2020 08:34:36 +0000 (16:34 +0800)
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
lang/golang/golang/files/go-gcc-helper

index 3d3f8935d533b20901c7d5533fbd067cbbae8f8e..b396e302c69dbbf6211fe6a9e891f6f839267900 100644 (file)
@@ -1,23 +1,41 @@
 #!/bin/sh
 
 me=go-gcc-helper
-name=$(basename $0)
+name="${0##*/}"
 
-case $name in
+log() {
+       # shellcheck disable=SC2039
+       local IFS=" "
+       printf '%s\n' "$me: $*"
+}
+
+case "$name" in
 gcc)
-       cmd=$GO_GCC_HELPER_CC
+       if [ -z "$GO_GCC_HELPER_CC" ]; then
+               log "missing GO_GCC_HELPER_CC"
+               exit 1
+       fi
+       cmd="$GO_GCC_HELPER_CC"
        ;;
 g++)
-       cmd=$GO_GCC_HELPER_CXX
+       if [ -z "$GO_GCC_HELPER_CXX" ]; then
+               log "missing GO_GCC_HELPER_CXX"
+               exit 1
+       fi
+       cmd="$GO_GCC_HELPER_CXX"
        ;;
 *)
-       echo "$me: unknown command \"$name\""
+       log "unknown command \"$name\""
        exit 1
        ;;
 esac
 
-export PATH="$GO_GCC_HELPER_PATH"
+if [ -n "$GO_GCC_HELPER_PATH" ]; then
+       export PATH="$GO_GCC_HELPER_PATH"
+else
+       log "missing GO_GCC_HELPER_PATH"
+fi
 
-echo "$me: running $cmd $@"
+log "running $cmd $*"
 
 $cmd "$@"