1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00

feat: add force color in color ext pkg (#8767)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-10-28 17:32:48 +02:00 committed by GitHub
parent 703f7a7666
commit bd72e42bfe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 8 deletions

View file

@ -13,7 +13,7 @@ var (
)
func Init(noColor bool) {
color.Init(noColor)
color.Init(noColor, false)
if !noColor {
HeaderBgColor = tablewriter.BgBlackColor
HeaderFgColor = tablewriter.FgGreenColor

View file

@ -4,17 +4,22 @@ import (
"github.com/fatih/color"
)
// Color is an alias to color.Color
type Color = color.Color
var (
BoldGreen *color.Color
BoldRed *color.Color
BoldYellow *color.Color
BoldFgCyan *color.Color
BoldGreen *Color
BoldRed *Color
BoldYellow *Color
BoldFgCyan *Color
)
func Init(noColor bool) {
toggleColor := func(c *color.Color) *color.Color {
func Init(noColor bool, force bool) {
toggleColor := func(c *Color) *Color {
if noColor {
c.DisableColor()
} else if force {
c.EnableColor()
}
return c
}

View file

@ -8,14 +8,23 @@ func TestInit(t *testing.T) {
tests := []struct {
name string
noColor bool
force bool
}{{
noColor: true,
force: false,
}, {
noColor: true,
force: true,
}, {
noColor: false,
force: false,
}, {
noColor: false,
force: true,
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Init(tt.noColor)
Init(tt.noColor, tt.force)
})
}
}