-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.go
59 lines (47 loc) · 1.29 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 texd
import (
"fmt"
"io"
)
// Versioning variables. These are set at compile time through -ldflags.
var (
version = "development"
commit = "HEAD"
commitat = "unknown"
buildat = "unknown"
isdev = "1"
)
const banner = `
_____ _ _ ____ texd version %s
| ____ \_/ | \ commit %s
| |___ _/ \_ |___/ commit date %s
|___ build date %s
`
type versionData struct{ version, commit, commitat, buildat, isdev string }
var v = versionData{version, commit, commitat, buildat, isdev}
func (d *versionData) Version() string {
if d.Development() {
return d.version + " (development)"
}
return d.version + " (release)"
}
func (d *versionData) Development() bool {
return d.isdev == "1"
}
func (d *versionData) PrintBanner(w io.Writer) {
fmt.Fprintf(w, banner, d.Version(), d.commit, d.commitat, d.buildat)
}
// Version returns a string describing the version. For release versions
// this will contain the Git tag and commit ID. When used as library (or
// in development), this may return just "development".
func Version() string {
return v.Version()
}
func Development() bool {
return v.Development()
}
// PrintBanner will write a small ASCII graphic and versioning
// information to w.
func PrintBanner(w io.Writer) {
v.PrintBanner(w)
}