44 "fmt"
55 "io"
66 "os"
7+ "regexp"
78 "strings"
89
910 "github.com/github/gh-cli/api"
@@ -19,9 +20,13 @@ var Version = "DEV"
1920// BuildDate is dynamically set at build time in the Makefile
2021var BuildDate = "YYYY-MM-DD"
2122
23+ var versionOutput = ""
24+
2225func init () {
2326 RootCmd .Version = fmt .Sprintf ("%s (%s)" , strings .TrimPrefix (Version , "v" ), BuildDate )
27+ versionOutput = fmt .Sprintf ("gh version %s\n %s\n " , RootCmd .Version , changelogURL (RootCmd .Version ))
2428 RootCmd .AddCommand (versionCmd )
29+ RootCmd .SetVersionTemplate (versionOutput )
2530
2631 RootCmd .PersistentFlags ().StringP ("repo" , "R" , "" , "Select another repository using the `OWNER/REPO` format" )
2732 RootCmd .PersistentFlags ().Bool ("help" , false , "Show help for command" )
@@ -56,7 +61,7 @@ var versionCmd = &cobra.Command{
5661 Use : "version" ,
5762 Hidden : true ,
5863 Run : func (cmd * cobra.Command , args []string ) {
59- fmt .Printf ("gh version %s \n " , RootCmd . Version )
64+ fmt .Printf (versionOutput )
6065 },
6166}
6267
@@ -128,3 +133,15 @@ func colorableErr(cmd *cobra.Command) io.Writer {
128133 }
129134 return err
130135}
136+
137+ func changelogURL (version string ) string {
138+ path := "https://github.com/github/homebrew-gh"
139+ r := regexp .MustCompile (`^v\d+\.\d+.\d+$` )
140+ if ! r .MatchString (version ) {
141+ return fmt .Sprintf ("%s/releases/latest" , path )
142+ }
143+
144+ tag := version
145+ url := fmt .Sprintf ("%s/releases/tag/%s" , path , tag )
146+ return url
147+ }
0 commit comments