Skip to content

Commit

Permalink
add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
martinnirtl committed Mar 29, 2023
1 parent 701c88c commit e980781
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
12 changes: 6 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 3 additions & 20 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit e980781

Please sign in to comment.