在一个“可通过go get获取”的包中选择一个不同的可执行文件名。

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

Choose a different executable name in a "go-getable" package

问题

是否可能拥有一个可通过go get获取的cli包(package main),但二进制文件安装时使用不同的名称?

例如,有一个名为github.com/exaring/foo-cli的代码库,

但是go get github.com/foo/foo-cli将安装一个名为foo(而不是foo-cli)的二进制文件?

重点是拥有一个表达力强的代码库名称,但可执行文件的名称要短且易于输入。

英文:

Is it possible to have a cli-package (package main) which is "go-getable", but the binary is installed under a different name?

For example to have a repository
github.com/exaring/foo-cli

But go get github.com/foo/foo-cli would install a binary called foo (not foo-cli)?

The point is to have an expressive repository name but a short and easy to type executable.

答案1

得分: 1

如果你不介意用户运行go build而不是go get,你可以这样做:

go build -o foo github.com/foo/foo-cli

否则,你可以将所有的CLI代码放在foo-cli中,并将main函数放在foo中。

英文:

If you're fine with the user running go build instead of go get, you can do this:

go build -o foo github.com/foo/foo-cli

Otherwise, you can keep all the CLI code in foo-cli and put the main function in foo.

huangapple
  • 本文由 发表于 2017年3月2日 22:55:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/42558701.html
匿名

发表评论

匿名网友

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

确定