-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmd_version.go
47 lines (40 loc) · 990 Bytes
/
cmd_version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"fmt"
"github.com/spf13/cobra"
)
var (
versionCmd = &cobra.Command{
Use: "version",
Aliases: []string{"info"},
Short: "Show build informations of Enifi exporter",
Long: "Display build commit, date, and version of Unifi exporter",
Run: versionCmdFn,
}
format string
)
func init() {
RootCmd.AddCommand(versionCmd)
versionCmd.Flags().StringVarP(&format, "format", "f", "text", "Output format (text, json)")
}
func versionCmdFn(cmd *cobra.Command, args []string) {
switch format {
case "json":
txt, _ := json.MarshalIndent(map[string]interface{}{
"name": "Unifi exporter",
"version": version,
"build": map[string]string{
"commit": commit,
"date": date,
},
}, "", " ")
fmt.Println(string(txt))
default:
fmt.Println("Unifi exporter")
fmt.Println("==============")
fmt.Println("Version: " + version)
fmt.Println("Git commit: " + commit)
fmt.Println("Build date: " + date)
}
}