@@ -36,6 +36,7 @@ func InitAndExecute() {
36
36
type flagpole struct {
37
37
logLevel string
38
38
genericCliConfigFlags * genericclioptions.ConfigFlags
39
+ disableColor bool
39
40
}
40
41
41
42
func setupRootCommand () * cobra.Command {
@@ -55,6 +56,7 @@ It colors the values based on "severity" [red: > 75% (too high); yellow: < 25% (
55
56
}
56
57
57
58
rootCmd .PersistentFlags ().StringVarP (& flags .logLevel , "verbosity" , "v" , "info" , "log level; one of [info, debug, trace, warn, error, fatal, panic]" )
59
+ rootCmd .Flags ().BoolVarP (& flags .disableColor , "disable-color" , "d" , false , "boolean flag for disabling colored output" )
58
60
59
61
flags .genericCliConfigFlags = genericclioptions .NewConfigFlags (false )
60
62
flags .genericCliConfigFlags .AddFlags (rootCmd .Flags ())
@@ -82,28 +84,33 @@ func runRootCommand(flags *flagpole) error {
82
84
}
83
85
log .Infof ("Either no volumes found in namespace/s: '%s' or the storage provisioner used for the volumes does not publish metrics to kubelet" , ns )
84
86
} else {
85
- PrintUsingGoPretty (sliceOfOutputRowPVC )
87
+ PrintUsingGoPretty (sliceOfOutputRowPVC , flags . disableColor )
86
88
}
87
89
88
90
return nil
89
91
}
90
92
91
- func PrintUsingGoPretty (sliceOfOutputRowPVC []* OutputRowPVC ) {
93
+ func PrintUsingGoPretty (sliceOfOutputRowPVC []* OutputRowPVC , disableColor bool ) {
94
+ if disableColor {
95
+ text .DisableColors ()
96
+ }
92
97
// https://github.com/jedib0t/go-pretty/tree/v6.0.4/table
93
98
t := table .NewWriter ()
94
99
95
100
t .AppendHeader (table.Row {"PV Name" , "PVC Name" , "Namespace" , "Node Name" , "Pod Name" , "Volume Mount Name" , "Size" , "Used" , "Available" , "%Used" , "iused" , "ifree" , "%iused" })
96
- hiWhiteColor := text .FgHiWhite
101
+ var whiteColor = text .FgWhite
102
+ var percentageUsedColor text.Color
103
+ var percentageIUsedColor text.Color
97
104
for _ , pvcRow := range sliceOfOutputRowPVC {
98
- percentageUsedColor : = GetColorFromPercentageUsed (pvcRow .PercentageUsed )
99
- percentageIUsedColor : = GetColorFromPercentageUsed (pvcRow .PercentageIUsed )
105
+ percentageUsedColor = GetColorFromPercentageUsed (pvcRow .PercentageUsed )
106
+ percentageIUsedColor = GetColorFromPercentageUsed (pvcRow .PercentageIUsed )
100
107
t .AppendRow ([]interface {}{
101
- hiWhiteColor .Sprintf ("%s" , pvcRow .PVName ),
102
- hiWhiteColor .Sprintf ("%s" , pvcRow .PVCName ),
103
- hiWhiteColor .Sprintf ("%s" , pvcRow .Namespace ),
104
- hiWhiteColor .Sprintf ("%s" , pvcRow .NodeName ),
105
- hiWhiteColor .Sprintf ("%s" , pvcRow .PodName ),
106
- hiWhiteColor .Sprintf ("%s" , pvcRow .VolumeMountName ),
108
+ fmt .Sprintf ("%s" , pvcRow .PVName ),
109
+ fmt .Sprintf ("%s" , pvcRow .PVCName ),
110
+ fmt .Sprintf ("%s" , pvcRow .Namespace ),
111
+ fmt .Sprintf ("%s" , pvcRow .NodeName ),
112
+ fmt .Sprintf ("%s" , pvcRow .PodName ),
113
+ fmt .Sprintf ("%s" , pvcRow .VolumeMountName ),
107
114
percentageUsedColor .Sprintf ("%s" , ConvertQuantityValueToHumanReadableIECString (pvcRow .CapacityBytes )),
108
115
percentageUsedColor .Sprintf ("%s" , ConvertQuantityValueToHumanReadableIECString (pvcRow .UsedBytes )),
109
116
percentageUsedColor .Sprintf ("%s" , ConvertQuantityValueToHumanReadableIECString (pvcRow .AvailableBytes )),
@@ -118,7 +125,7 @@ func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
118
125
styleBold := table .StyleBold
119
126
styleBold .Options = table .OptionsNoBordersAndSeparators
120
127
t .SetStyle (styleBold )
121
- t .Style ().Color .Header = text.Colors {hiWhiteColor , text .Bold }
128
+ t .Style ().Color .Header = text.Colors {whiteColor , text .Bold }
122
129
// t.Style().Options.SeparateRows = true
123
130
// t.SetAutoIndex(true)
124
131
// t.SetOutputMirror(os.Stdout)
@@ -127,11 +134,11 @@ func PrintUsingGoPretty(sliceOfOutputRowPVC []*OutputRowPVC) {
127
134
128
135
func GetColorFromPercentageUsed (percentageUsed float64 ) text.Color {
129
136
if percentageUsed > 75 {
130
- return text .FgHiRed
137
+ return text .FgRed
131
138
} else if percentageUsed < 25 {
132
- return text .FgHiYellow
139
+ return text .FgYellow
133
140
} else {
134
- return text .FgHiGreen
141
+ return text .FgGreen
135
142
}
136
143
}
137
144
0 commit comments