/
version.go
51 lines (41 loc) 路 1.09 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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of K9s
package cmd
import (
"fmt"
"github.com/derailed/k9s/internal/color"
"github.com/spf13/cobra"
)
func versionCmd() *cobra.Command {
var short bool
command := cobra.Command{
Use: "version",
Short: "Print version/build info",
Long: "Print version/build information",
Run: func(cmd *cobra.Command, args []string) {
printVersion(short)
},
}
command.PersistentFlags().BoolVarP(&short, "short", "s", false, "Prints K9s version info in short format")
return &command
}
func printVersion(short bool) {
const fmat = "%-20s %s\n"
var outputColor color.Paint
if short {
outputColor = -1
} else {
outputColor = color.Cyan
printLogo(outputColor)
}
printTuple(fmat, "Version", version, outputColor)
printTuple(fmat, "Commit", commit, outputColor)
printTuple(fmat, "Date", date, outputColor)
}
func printTuple(fmat, section, value string, outputColor color.Paint) {
if outputColor != -1 {
fmt.Fprintf(out, fmat, color.Colorize(section+":", outputColor), value)
return
}
fmt.Fprintf(out, fmat, section, value)
}