diff --git a/command/root.go b/command/root.go index 6bf99c229..77cb51a48 100644 --- a/command/root.go +++ b/command/root.go @@ -20,9 +20,13 @@ var Version = "DEV" // 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) + versionOutput = fmt.Sprintf("gh version %s\n%s\n", RootCmd.Version, changelogURL(RootCmd.Version)) RootCmd.AddCommand(versionCmd) + RootCmd.SetVersionTemplate(versionOutput) RootCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format") RootCmd.PersistentFlags().Bool("help", false, "Show help for command") @@ -57,7 +61,7 @@ var versionCmd = &cobra.Command{ Use: "version", Hidden: true, Run: func(cmd *cobra.Command, args []string) { - fmt.Printf("gh version %s\n%s\n", RootCmd.Version, changelogURL(RootCmd.Version)) + fmt.Printf(versionOutput) }, }