“go install”命令能够用于安装与Git仓库中不同名称的可执行文件吗?

huangapple go评论83阅读模式
英文:

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

问题

Go有一个很好的功能,你可以使用go install <x>命令,它会下载、构建并安装一个二进制文件。

例如,在我的本地Windows PC上,go install github.com/goreleaser/goreleaser会找到goreleaser的最新版本,下载、构建并将其安装到我的本地二进制文件路径中。

我正在一个项目上工作,我们希望启用go install,但是如果GitHub仓库名称与可执行文件名称不匹配,就会遇到问题。GitHub CLI本身也遇到了完全相同的问题:

示例:

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

有没有办法解决这个问题?


更新:我发现我可以直接通过其子目录引用包。在我的特定情况下,这样可以工作:go install github.com/OctopusDeploy/cli/cmd/octopus@latest

这有点不太方便,但是可以正常工作。对于GitHub CLI来说,这种方法行不通,因为他们的go.mod文件中有一个replace指令 “go install”命令能够用于安装与Git仓库中不同名称的可执行文件吗?

问题:有没有办法让这个过程更加简洁?是否有一种方法可以使用go install github.com/OctopusDeploy/cli@latest而不是go install github.com/OctopusDeploy/cli/cmd/octopus@latest

英文:

Go has a nice feature where you can go install &lt;x&gt; 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 “go install”命令能够用于安装与Git仓库中不同名称的可执行文件吗?

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

得分: 1

这可以变得更好吗?有没有一种方法可以使用别名或配置文件,以便可以使用"go install github.com/OctopusDeploy/cli@latest"代替"go install github.com/OctopusDeploy/cli/cmd/octopus@latest"?

不可以。非常简单。

英文:

> 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.

huangapple
  • 本文由 发表于 2022年9月21日 05:22:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/73792788.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定