我想向cobra我的gocli 工具添加一个仅打印版本的命令
var version = "development"
// versionCmd prints mytool version
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print mytool version information",
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("mytool version", version)
return nil
},
}
我可以覆盖(或选择不这样做)version变量使用ldflags
▶ go build
▶ ./mytool version
mytool version development
▶ go build -ldflags "-X github.com/myprofile/mytool/cmd.version=$(git describe --tags --always)"
▶ ./mytool version
mytool version cffc487
但是,在执行go install行为更改时,我似乎无法覆盖versionvar,这是为什么呢?
▶ go build -ldflags "-X github.com/myprofile/mytool/cmd.version=$(git describe --tags --always)"
▶ go install
▶ ~/go/bin/mytool version
mytool version development
使用
▶ go version
go version go1.14 darwin/amd64
UYOU
相关分类