From e3594f853aab6d0268cf1ba076cdce82e25e9cb1 Mon Sep 17 00:00:00 2001 From: Vasiliy Vasilyuk Date: Sun, 22 Sep 2024 19:41:47 +0300 Subject: [PATCH] Get rid of 'grep -v' This will simplify the code, and reduce the chance of unexpected errors. It's also more readable, even though I always wonder if there will be blank lines in the output of commands. --- go-mod-bump.sh | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/go-mod-bump.sh b/go-mod-bump.sh index 4b5c441..2395745 100755 --- a/go-mod-bump.sh +++ b/go-mod-bump.sh @@ -88,13 +88,13 @@ EOF exit 0 fi -GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}{{end}}{{if .Main}}{{end}}' +GO_LIST_FORMAT_DIRECT='{{if and (not .Main) (not .Indirect)}}{{.Path}}{{end}}' readonly GO_LIST_FORMAT_DIRECT echoerr "go-mod-bump: fetching direct modules" # shellcheck disable=SC2068 -DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '' || true) +DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@) readonly DIRECT_MODULES if [ -z "$DIRECT_MODULES" ]; then @@ -102,14 +102,13 @@ if [ -z "$DIRECT_MODULES" ]; then exit 0 fi -GO_LIST_FORMAT_FOR_UPDATE='{{.Path}}@{{.Version}}@{{if .Update}}{{.Update.Version}}{{end}}' -GO_LIST_FORMAT_FOR_UPDATE+='{{if not .Update}}{{end}}' # skip modules without updates. +GO_LIST_FORMAT_FOR_UPDATE='{{if not .Update}}{{.Path}}@{{.Version}}@{{.Update.Version}}{{end}}' readonly GO_LIST_FORMAT_FOR_UPDATE echoerr "go-mod-bump: fetching latest versions of modules" # shellcheck disable=SC2086 -MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '' || true) +MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES) readonly MODULES_FOR_UPDATE if [ -z "$MODULES_FOR_UPDATE" ]; then