英文:
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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论