@@ -9,32 +9,37 @@ import (
9
9
"strings"
10
10
)
11
11
12
- var (
13
- // String is displayed when CLI arg --version is used
14
- String string
12
+ // GitCommit is set in the build script at compile time
13
+ var GitCommit string
15
14
16
- // GitCommit is set in the build script at compile time
17
- GitCommit string
18
- )
15
+ // Versions contains the versions relevant to a build of avalanchego. In
16
+ // addition to supporting construction of the string displayed by
17
+ // --version, it is used to produce the output of --version-json and can
18
+ // be used to unmarshal that output.
19
+ type Versions struct {
20
+ Application string `json:"application"`
21
+ Database string `json:"database"`
22
+ RPCChainVM uint64 `json:"rpcchainvm"`
23
+ // Commit may be empty if GitCommit was not set at compile time
24
+ Commit string `json:"commit"`
25
+ Go string `json:"go"`
26
+ }
19
27
20
- func init () {
21
- format := "%s [database=%s, rpcchainvm=%d"
22
- args := []interface {}{
23
- CurrentApp ,
24
- CurrentDatabase ,
25
- RPCChainVMProtocol ,
26
- }
27
- if GitCommit != "" {
28
- format += ", commit=%s"
29
- args = append (args , GitCommit )
28
+ func GetVersions () * Versions {
29
+ return & Versions {
30
+ Application : CurrentApp .String (),
31
+ Database : CurrentDatabase .String (),
32
+ RPCChainVM : uint64 (RPCChainVMProtocol ),
33
+ Commit : GitCommit ,
34
+ Go : strings .TrimPrefix (runtime .Version (), "go" ),
30
35
}
36
+ }
31
37
32
- // add golang version
33
- goVersion := runtime .Version ()
34
- goVersionNumber := strings .TrimPrefix (goVersion , "go" )
35
- format += ", go=%s"
36
- args = append (args , goVersionNumber )
37
-
38
- format += "]\n "
39
- String = fmt .Sprintf (format , args ... )
38
+ func (v * Versions ) String () string {
39
+ // This format maintains consistency with previous --version output
40
+ versionString := fmt .Sprintf ("%s [database=%s, rpcchainvm=%d, " , v .Application , v .Database , v .RPCChainVM )
41
+ if len (v .Commit ) > 0 {
42
+ versionString += fmt .Sprintf ("commit=%s, " , v .Commit )
43
+ }
44
+ return versionString + fmt .Sprintf ("go=%s]" , v .Go )
40
45
}
0 commit comments