We are working with Go modules. I want in a CLI to get the specific version of a module. Is it possible?
If you are curious, the reason is that I want to add the following generate
command:
//go:generate go run github.com/golang/mock/mockgen -source="$GOPATH/pkg/mod/mymodules.com/mymodule@${VERSION}/module.go" -destination=module_mock.go
So I need to somehow get the version
Basics:
go list -m all
— View final versions that will be used in a build for all direct and indirect dependencies
go list -u -m all
— View available minor and patch upgrades for all direct and indirect dependencies
Example:
To get the version of a specific module, let's say golang.org/x/text
go list -m all | grep golang.org/x/text | awk '{print $2}'
or
go list -u -m all | grep golang.org/x/text | awk '{print $2}'
So, the general way:
go list -u -m all | grep <module-name> | awk '{print $2}'