package cmd import ( "fmt" "git.bloy.org/mike/gotest/version" "github.com/spf13/cobra" "github.com/spf13/viper" ) var showCfg bool func init() { rootCmd.AddCommand(versionCmd) versionCmd.Flags().BoolVarP(&showCfg, "long", "l", false, "Show the configuration as well as the version") } var versionCmd = &cobra.Command{ Use: "version", Short: "Print the version number", Long: "All software has versions. This is how you see it.", Run: func(cmd *cobra.Command, args []string) { fmt.Printf("This is GoTest %s\n\n", version.Version) fmt.Printf(" Config location: %s\n", viper.ConfigFileUsed()) if showCfg { fmt.Println("\nConfiguration Data:") for _, key := range viper.AllKeys() { fmt.Printf(" %s: %t\n", key, viper.Get(key)) } } }, }