Skip to content

Commit ced6809

Browse files
committed
add changelog to --version
1 parent 1921a74 commit ced6809

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

command/root.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ var Version = "DEV"
2020
// BuildDate is dynamically set at build time in the Makefile
2121
var BuildDate = "YYYY-MM-DD"
2222

23+
var versionOutput = ""
24+
2325
func init() {
2426
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))
2528
RootCmd.AddCommand(versionCmd)
29+
RootCmd.SetVersionTemplate(versionOutput)
2630

2731
RootCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format")
2832
RootCmd.PersistentFlags().Bool("help", false, "Show help for command")
@@ -57,7 +61,7 @@ var versionCmd = &cobra.Command{
5761
Use: "version",
5862
Hidden: true,
5963
Run: func(cmd *cobra.Command, args []string) {
60-
fmt.Printf("gh version %s\n%s\n", RootCmd.Version, changelogURL(RootCmd.Version))
64+
fmt.Printf(versionOutput)
6165
},
6266
}
6367

0 commit comments

Comments
 (0)