-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
59 lines (49 loc) · 1.21 KB
/
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
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
"runtime"
"strings"
"github.com/pelletier/go-toml/v2"
"github.com/spf13/cobra"
"github.com/bandprotocol/falcon/relayer"
)
var (
// Version defines the application version (defined at compile time)
Version = ""
Commit = ""
Dirty = ""
)
type versionInfo struct {
Version string `json:"version" yaml:"version"`
Commit string `json:"commit" yaml:"commit"`
Go string `json:"go" yaml:"go"`
}
// versionCmd returns a command that prints the falcon version information.
func versionCmd(_ *relayer.App) *cobra.Command {
versionCmd := &cobra.Command{
Use: "version",
Aliases: []string{"v"},
Short: "Print the falcon version info",
Args: withUsage(cobra.NoArgs),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s version
$ %s v`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
commit := Commit
if Dirty != "0" {
commit += " (dirty)"
}
verInfo := versionInfo{
Version: Version,
Commit: commit,
Go: fmt.Sprintf("%s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
}
bz, err := toml.Marshal(&verInfo)
fmt.Fprintln(cmd.OutOrStdout(), string(bz))
return err
},
}
return versionCmd
}