add changelog to --version

This commit is contained in:
Corey Johnson 2020-01-13 11:14:45 -08:00
parent 1921a74eec
commit ced6809e1e

View file

@ -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)
},
}