Merge pull request #491 from arnottcr/version

command: default to toolchain version
This commit is contained in:
Mislav Marohnić 2020-02-18 14:04:16 +01:00 committed by GitHub
commit 75b7e9588a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import (
"io"
"os"
"regexp"
"runtime/debug"
"strings"
"github.com/cli/cli/api"
@ -15,16 +16,26 @@ import (
"github.com/spf13/cobra"
)
// Version is dynamically set at build time in the Makefile
// Version is dynamically set by the toolchain or overriden by the Makefile.
var Version = "DEV"
// BuildDate is dynamically set at build time in the Makefile
var BuildDate = "YYYY-MM-DD"
// BuildDate is dynamically set at build time in the Makefile.
var BuildDate = "" // YYYY-MM-DD
var versionOutput = ""
func init() {
RootCmd.Version = fmt.Sprintf("%s (%s)", strings.TrimPrefix(Version, "v"), BuildDate)
if Version == "DEV" {
if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "(devel)" {
Version = info.Main.Version
}
}
Version = strings.TrimPrefix(Version, "v")
if BuildDate == "" {
RootCmd.Version = Version
} else {
RootCmd.Version = fmt.Sprintf("%s (%s)", Version, BuildDate)
}
versionOutput = fmt.Sprintf("gh version %s\n%s\n", RootCmd.Version, changelogURL(Version))
RootCmd.AddCommand(versionCmd)
RootCmd.SetVersionTemplate(versionOutput)