32 lines
693 B
Go
32 lines
693 B
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
goVersion "go.hein.dev/go-version"
|
|
)
|
|
|
|
var (
|
|
shortened = false
|
|
version = "dev"
|
|
commit = "none"
|
|
date = "unknown"
|
|
output = "json"
|
|
)
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Version will output the current build information",
|
|
Long: ``,
|
|
Run: func(_ *cobra.Command, _ []string) {
|
|
resp := goVersion.FuncWithOutput(shortened, version, commit, date, output)
|
|
fmt.Print(resp)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
versionCmd.Flags().BoolVarP(&shortened, "short", "s", false, "Print just the version number.")
|
|
versionCmd.Flags().StringVarP(&output, "output", "o", "json", "Output format. One of 'yaml' or 'json'.")
|
|
}
|