Skip to content

Commit

Permalink
Get rid of 'grep -v'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xorcare committed Sep 22, 2024
1 parent aae1af1 commit 3cbad09
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions go-mod-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,28 +88,27 @@ EOF
exit 0
fi

GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}<SKIP>{{end}}{{if .Main}}<SKIP>{{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 '<SKIP>' || true)
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@)
readonly DIRECT_MODULES

if [ -z "$DIRECT_MODULES" ]; then
echoerr "go-mod-bump: nothing to update (no direct modules found)"
exit 0
fi

GO_LIST_FORMAT_FOR_UPDATE='{{.Path}}@{{.Version}}@{{if .Update}}{{.Update.Version}}{{end}}'
GO_LIST_FORMAT_FOR_UPDATE+='{{if not .Update}}<SKIP>{{end}}' # skip modules without updates.
GO_LIST_FORMAT_FOR_UPDATE='{{if .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 '<SKIP>' || 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
Expand Down

0 comments on commit 3cbad09

Please sign in to comment.