derision-test / go-mockgen

MIT License
57 stars 7 forks source link

How to install the go-mockgen binary ? #29

Open nathani-axis opened 2 years ago

nathani-axis commented 2 years ago

Hello,

I'm using go-mockgen in one of my projects, where I have it run in a bash script. I see in the README that the installation instructions are:

go get -u github.com/derision-test/go-mockgen/...

but as that's the old way of installing tools, go complains, and asks me to use go install instead.

So my bash script includes:

go install github.com/derision-test/go-mockgen/...
go generate ./...

When I run by bash script though, I get this output:

../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/cmd/go-mockgen/args.go:11:2: missing go.sum entry for module providing package github.com/alecthomas/kingpin (imported by github.com/derision-test/go-mockgen/cmd/go-mockgen);
 to add:                                                                                                                                                                                                                                        
        go get github.com/derision-test/go-mockgen/cmd/go-mockgen@v1.2.0                                                                                                                                                                        
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/internal/mockgen/generation/generate.go:13:2: missing go.sum entry for module providing package github.com/dave/jennifer/jen (imported by github.com/derision-test/go-mockgen/
internal/mockgen/generation); to add:                                                                                                                                                                                                           
        go get github.com/derision-test/go-mockgen/internal/mockgen/generation@v1.2.0                                                                                                                                                           
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/internal/mockgen/generation/generate_structs.go:9:2: missing go.sum entry for module providing package github.com/dustin/go-humanize (imported by github.com/derision-test/go-
mockgen/internal/mockgen/generation); to add:                                                                                                                                                                                                   
        go get github.com/derision-test/go-mockgen/internal/mockgen/generation@v1.2.0                                                                                                                                                           
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/internal/mockgen/generation/generate_comment.go:8:2: missing go.sum entry for module providing package github.com/mitchellh/go-wordwrap (imported by github.com/derision-test/
go-mockgen/internal/mockgen/generation); to add:                                                                                                                                                                                                
        go get github.com/derision-test/go-mockgen/internal/mockgen/generation@v1.2.0                                                                                                                                                           
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/internal/mockgen/types/extract.go:13:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages (imported by github.com/derision-test/go-mockgen/inte
rnal/mockgen/types); to add:                                                                                                                                                                                                                    
        go get github.com/derision-test/go-mockgen/internal/mockgen/types@v1.2.0                                                                                                                                                                
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/testutil/gomega/anything_matcher.go:6:2: missing go.sum entry for module providing package github.com/onsi/gomega/format (imported by github.com/derision-test/go-mockgen/test
util/gomega); to add:                                                                                                                                                                                                                           
        go get github.com/derision-test/go-mockgen/testutil/gomega@v1.2.0                                                                                                                                                                       
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/testutil/gomega/called_with_matcher.go:8:2: missing go.sum entry for module providing package github.com/onsi/gomega/matchers (imported by github.com/derision-test/go-mockgen
/testutil/gomega); to add:                                                                                                                                                                                                                      
        go get github.com/derision-test/go-mockgen/testutil/gomega@v1.2.0                                                                                                                                                                       
../../../../go/pkg/mod/github.com/derision-test/go-mockgen@v1.2.0/testutil/gomega/anything_matcher.go:7:2: missing go.sum entry for module providing package github.com/onsi/gomega/types (imported by github.com/derision-test/go-mockgen/testu
til/gomega); to add:                                                                                                                                                                                                                            
        go get github.com/derision-test/go-mockgen/testutil/gomega@v1.2.0

These missing entries are not actually missing entries, as I don't want them in my go project. go-mockgen is a tool I want to run on the project, but I don't necessarily want to add it as dependencies for my project.

Moreover, if I do run all the go get commands that are listed, whenever I will run go mod tidy, they will be removed, as they are not actually dependencies in my code.

Thanks

efritz commented 2 years ago

I believe that if you do a go install with an explicit version tag that it won't add it to your containing project. This StackOverflow solution indicates that could be a solution for you.

Could you try it and let me know if that works? I can update the installation instructions if you'd find them more clear.

w32blaster commented 2 years ago

I had the same issue and I fixed it by installing the tool via:

go install github.com/derision-test/go-mockgen/...@v1.3.1