diff --git a/cmd/root.go b/cmd/root.go index cf7faa3..cb6e9e3 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -23,16 +23,16 @@ package cmd import ( "os" + "time" "github.com/spf13/cobra" ) -// VersionInfo describes structure of version information objects. -type VersionInfo struct { - Version string - Commit string - Date string -} +var ( + version = "development" + commit = "na" + date = time.Now().Local().Format(time.ANSIC) +) var rootCmd = &cobra.Command{ Use: "hosts", diff --git a/cmd/version.go b/cmd/version.go index f6eb48f..62e8dbd 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -22,36 +22,19 @@ THE SOFTWARE. package cmd import ( - "fmt" - "github.com/spf13/cobra" ) // versionCmd represents the version command var versionCmd = &cobra.Command{ Use: "version", - Short: "A brief description of your command", - Long: `A longer description that spans multiple lines and likely contains examples -and usage of using your command. For example: - -Cobra is a CLI library for Go that empowers applications. -This application is a tool to generate the needed files -to quickly create a Cobra application.`, + Short: "Print CLI version information", + Long: `Print CLI version information.`, Run: func(cmd *cobra.Command, args []string) { - fmt.Println("version called") + cmd.Printf("Hosts CLI Version %s built on %s (commit: %s)\n", version, date, commit) }, } func init() { rootCmd.AddCommand(versionCmd) - - // Here you will define your flags and configuration settings. - - // Cobra supports Persistent Flags which will work for this command - // and all subcommands, e.g.: - // versionCmd.PersistentFlags().String("foo", "", "A help for foo") - - // Cobra supports local flags which will only run when this command - // is called directly, e.g.: - // versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") }