Skip to content

Commit 3cbad09

Browse files
committed
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.
1 parent aae1af1 commit 3cbad09

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

go-mod-bump.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -88,28 +88,27 @@ EOF
8888
exit 0
8989
fi
9090

91-
GO_LIST_FORMAT_DIRECT='{{.Path}}{{if .Indirect}}<SKIP>{{end}}{{if .Main}}<SKIP>{{end}}'
91+
GO_LIST_FORMAT_DIRECT='{{if and (not .Main) (not .Indirect)}}{{.Path}}{{end}}'
9292
readonly GO_LIST_FORMAT_DIRECT
9393

9494
echoerr "go-mod-bump: fetching direct modules"
9595

9696
# shellcheck disable=SC2068
97-
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@ | grep -v '<SKIP>' || true)
97+
DIRECT_MODULES=$(go list -m -f "$GO_LIST_FORMAT_DIRECT" $@)
9898
readonly DIRECT_MODULES
9999

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

105-
GO_LIST_FORMAT_FOR_UPDATE='{{.Path}}@{{.Version}}@{{if .Update}}{{.Update.Version}}{{end}}'
106-
GO_LIST_FORMAT_FOR_UPDATE+='{{if not .Update}}<SKIP>{{end}}' # skip modules without updates.
105+
GO_LIST_FORMAT_FOR_UPDATE='{{if .Update}}{{.Path}}@{{.Version}}@{{.Update.Version}}{{end}}'
107106
readonly GO_LIST_FORMAT_FOR_UPDATE
108107

109108
echoerr "go-mod-bump: fetching latest versions of modules"
110109

111110
# shellcheck disable=SC2086
112-
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES | grep -v '<SKIP>' || true)
111+
MODULES_FOR_UPDATE=$(go list -m -u -f "$GO_LIST_FORMAT_FOR_UPDATE" $DIRECT_MODULES)
113112
readonly MODULES_FOR_UPDATE
114113

115114
if [ -z "$MODULES_FOR_UPDATE" ]; then

0 commit comments

Comments
 (0)