File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 55 "io"
66 "os"
77 "regexp"
8+ "runtime/debug"
89 "strings"
910
1011 "github.com/cli/cli/api"
@@ -15,16 +16,26 @@ import (
1516 "github.com/spf13/cobra"
1617)
1718
18- // Version is dynamically set at build time in the Makefile
19+ // Version is dynamically set by the toolchain or overriden by the Makefile.
1920var Version = "DEV"
2021
21- // BuildDate is dynamically set at build time in the Makefile
22- var BuildDate = "YYYY-MM-DD"
22+ // BuildDate is dynamically set at build time in the Makefile.
23+ var BuildDate = "" // YYYY-MM-DD
2324
2425var versionOutput = ""
2526
2627func init () {
27- RootCmd .Version = fmt .Sprintf ("%s (%s)" , strings .TrimPrefix (Version , "v" ), BuildDate )
28+ if Version == "DEV" {
29+ if info , ok := debug .ReadBuildInfo (); ok && info .Main .Version != "(devel)" {
30+ Version = info .Main .Version
31+ }
32+ }
33+ Version = strings .TrimPrefix (Version , "v" )
34+ if BuildDate == "" {
35+ RootCmd .Version = Version
36+ } else {
37+ RootCmd .Version = fmt .Sprintf ("%s (%s)" , Version , BuildDate )
38+ }
2839 versionOutput = fmt .Sprintf ("gh version %s\n %s\n " , RootCmd .Version , changelogURL (Version ))
2940 RootCmd .AddCommand (versionCmd )
3041 RootCmd .SetVersionTemplate (versionOutput )
You can’t perform that action at this time.
0 commit comments