Can 'go install' be made to work for executables with different names from the git repo?

437 Views Asked by At

Go has a nice feature where you can go install <x> and it will download, build and install a binary.

For example, on my local windows PC, go install github.com/goreleaser/goreleaser will find the latest release for goreleaser, download, build and install it to my local binaries path.

I am working on a project where we would like to enable go install, but encounter a problem if the github repo name does not match the executable name. The GitHub CLI itself runs into the exact same problem:

Example:

go install github.com/cli/cli@latest
go: downloading github.com/cli/cli v1.14.0
go: github.com/cli/cli@latest: module github.com/cli/cli@latest found (v1.14.0), but does not contain package github.com/cli/cli

Is there a way to resolve this?


Update: I worked out that I could directly reference the package via it's sub directory. In my particular instance this works: go install github.com/OctopusDeploy/cli/cmd/octopus@latest

This is a bit unpleasant, but works correctly. It doesn't work for the github CLI because their go.mod has a replace directive in it :-(

Question: Can this be made nicer? Is there a way to put some sort of alias or configuration file so that go install github.com/OctopusDeploy/cli@latest can be used instead of go install github.com/OctopusDeploy/cli/cmd/octopus@latest ?

1

There are 1 best solutions below

0
On BEST ANSWER

Can this be made nicer? Is there a way to put some sort of alias or configuration file so that go install github.com/OctopusDeploy/cli@latest can be used instead of go install github.com/OctopusDeploy/cli/cmd/octopus@latest ?

No. Dead simple.