14
14
name string
15
15
version = "dev build"
16
16
buildSource = "[source unknown]"
17
+ buildTime = "[build time unknown]"
17
18
license = "[license unknown]"
18
19
19
20
info * Info
@@ -25,19 +26,25 @@ type Info struct {
25
26
Name string
26
27
Version string
27
28
License string
28
- Commit string
29
- Time string
30
- Source string
31
- Dirty bool
29
+
30
+ Source string
31
+ BuildTime string
32
+
33
+ Commit string
34
+ CommitTime string
35
+ Dirty bool
32
36
33
37
debug.BuildInfo
34
38
}
35
39
36
40
// Set sets meta information via the main routine. This should be the first thing your program calls.
37
- func Set (setName string , setVersion string , setLicenseName string , compareVersionToTag bool ) {
41
+ func Set (setName string , setVersion string , setLicenseName string ) {
38
42
name = setName
39
- version = setVersion
40
43
license = setLicenseName
44
+
45
+ if setVersion != "" {
46
+ version = setVersion
47
+ }
41
48
}
42
49
43
50
// GetInfo returns all the meta information about the program.
@@ -50,14 +57,22 @@ func GetInfo() *Info {
50
57
}
51
58
52
59
info = & Info {
53
- Name : name ,
54
- Version : version ,
55
- License : license ,
56
- BuildInfo : * buildInfo ,
57
- Source : buildSource ,
58
- Commit : buildSettings ["vcs.revision" ],
59
- Time : buildSettings ["vcs.time" ],
60
- Dirty : buildSettings ["vcs.modified" ] == "true" ,
60
+ Name : name ,
61
+ Version : version ,
62
+ License : license ,
63
+ Source : buildSource ,
64
+ BuildTime : buildTime ,
65
+ Commit : buildSettings ["vcs.revision" ],
66
+ CommitTime : buildSettings ["vcs.time" ],
67
+ Dirty : buildSettings ["vcs.modified" ] == "true" ,
68
+ BuildInfo : * buildInfo ,
69
+ }
70
+
71
+ if info .Commit == "" {
72
+ info .Commit = "[commit unknown]"
73
+ }
74
+ if info .CommitTime == "" {
75
+ info .CommitTime = "[commit time unknown]"
61
76
}
62
77
})
63
78
@@ -78,14 +93,21 @@ func Version() string {
78
93
// FullVersion returns the full and detailed version string.
79
94
func FullVersion () string {
80
95
info := GetInfo ()
81
-
82
96
builder := new (strings.Builder )
83
97
84
- builder .WriteString (fmt .Sprintf ("%s\n version %s\n " , info .Name , Version ()))
98
+ // Name and version.
99
+ builder .WriteString (fmt .Sprintf ("%s %s\n " , info .Name , Version ()))
100
+
101
+ // Build info.
102
+ builder .WriteString (fmt .Sprintf ("\n built with %s (%s) %s/%s\n " , runtime .Version (), runtime .Compiler , runtime .GOOS , runtime .GOARCH ))
103
+ builder .WriteString (fmt .Sprintf (" at %s\n " , info .BuildTime ))
104
+
105
+ // Commit info.
85
106
builder .WriteString (fmt .Sprintf ("\n commit %s\n " , info .Commit ))
86
- builder .WriteString (fmt .Sprintf ("built with %s (%s) %s/%s\n " , runtime .Version (), runtime .Compiler , runtime .GOOS , runtime .GOARCH ))
87
- builder .WriteString (fmt .Sprintf (" on %s\n " , info .Time ))
88
- builder .WriteString (fmt .Sprintf ("\n Licensed under the %s license.\n The source code is available here: %s" , license , info .Source ))
107
+ builder .WriteString (fmt .Sprintf (" at %s\n " , info .CommitTime ))
108
+ builder .WriteString (fmt .Sprintf (" from %s\n " , info .Source ))
109
+
110
+ builder .WriteString (fmt .Sprintf ("\n Licensed under the %s license." , license ))
89
111
90
112
return builder .String ()
91
113
}
@@ -102,10 +124,6 @@ func CheckVersion() error {
102
124
if name == "[NAME]" || license == "[license unknown]" {
103
125
return errors .New ("must call SetInfo() before calling CheckVersion()" )
104
126
}
105
-
106
- if version == "[version unknown]" {
107
- return errors .New ("please build using the supplied build script.\n $ ./build {main.go|...}" )
108
- }
109
127
}
110
128
111
129
return nil
0 commit comments