-1

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 ?

Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
  • The only universal way to build a `main` package is to run `go install` or `go build` from within the module source. – JimB Sep 20 '22 at 21:24

1 Answers1

1

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.

Volker
  • 40,468
  • 7
  • 81
  • 87