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

import (
	"fmt"
	"os"

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

const (
	// Name of DTail.
	Name string = "DTail"
	// Version of DTail.
	Version string = "3.2.1"
	// Additional information for DTail
	Additional string = ""
	// ProtocolCompat -ibility version.
	ProtocolCompat string = "3"
)

// String representation of the DTail version.
func String() string {
	return fmt.Sprintf("%s %v Protocol %s %s", Name, Version, ProtocolCompat, Additional)
}

// PaintedString is a prettier string representation of the DTail version.
func PaintedString() string {
	if !color.Colored {
		return String()
	}
	name := color.Paint(color.Yellow, Name)
	version := color.Paint(color.Blue, Version)
	descr := color.Paint(color.Green, Additional)

	return fmt.Sprintf("%s %v Protocol %s %s", name, version, ProtocolCompat, descr)
}

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