summaryrefslogtreecommitdiff
path: root/internal/version/version.go
blob: c8ad394f8f862061daf01d0c21470787ff33f183 (plain)
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
package version

import (
	"fmt"
	"os"

	"github.com/mimecast/dtail/internal/color"
	"github.com/mimecast/dtail/internal/config"
	"github.com/mimecast/dtail/internal/protocol"
)

const (
	// Name of DTail.
	Name string = "DTail"
	// Version of DTail.
	Version string = "4.3.2"
	// 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() string {
	if !config.Client.TermColorsEnable {
		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() {
	fmt.Println(PaintedString())
}

// PrintAndExit prints the program version and exists.
func PrintAndExit() {
	Print()
	os.Exit(0)
}