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
|
package version
import (
"fmt"
"os"
"github.com/mimecast/dtail/internal/color"
"github.com/mimecast/dtail/internal/protocol"
)
const (
// Name of DTail.
Name string = "DTail"
// Version of DTail.
Version string = "4.3.2-ng"
// Additional information for DTail
Additional string = "Have a lot of fun!"
)
// String representation of the DTail version.
func String() string {
return fmt.Sprintf("%s %v Protocol %s %s", Name, Version,
protocol.ProtocolCompat, Additional)
}
// PaintedString is a prettier string representation of the DTail version.
func PaintedString(colorsEnabled bool) string {
if !colorsEnabled {
return String()
}
name := color.PaintStrWithAttr(fmt.Sprintf(" %s ", Name),
color.FgYellow, color.BgBlue, color.AttrBold)
version := color.PaintStrWithAttr(fmt.Sprintf(" %s ", Version),
color.FgBlue, color.BgYellow, color.AttrBold)
protocol := color.PaintStr(fmt.Sprintf(" Protocol %s ", protocol.ProtocolCompat),
color.FgBlack, color.BgGreen)
additional := color.PaintStrWithAttr(fmt.Sprintf(" %s ", Additional),
color.FgWhite, color.BgMagenta, color.AttrUnderline)
return fmt.Sprintf("%s%v%s%s", name, version, protocol, additional)
}
// Print the version.
func Print(colorsEnabled bool) {
fmt.Println(PaintedString(colorsEnabled))
}
// PrintAndExit prints the program version and exists.
func PrintAndExit(colorsEnabled bool) {
Print(colorsEnabled)
os.Exit(0)
}
|