mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-05 07:26:55 +00:00
chore: init ext packages (#8758)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
f90ba25050
commit
619c3baab2
9 changed files with 74 additions and 41 deletions
|
@ -76,7 +76,7 @@ func Command() *cobra.Command {
|
|||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
out := cmd.OutOrStdout()
|
||||
color.InitColors(removeColor)
|
||||
color.Init(removeColor)
|
||||
applyCommandConfig.PolicyPaths = args
|
||||
rc, _, skipInvalidPolicies, responses, err := applyCommandConfig.applyCommandHelper(out)
|
||||
if err != nil {
|
||||
|
|
|
@ -30,7 +30,7 @@ func Command() *cobra.Command {
|
|||
Args: cobra.MinimumNArgs(1),
|
||||
SilenceUsage: true,
|
||||
RunE: func(cmd *cobra.Command, dirPath []string) (err error) {
|
||||
color.InitColors(removeColor)
|
||||
color.Init(removeColor)
|
||||
store.SetRegistryAccess(registryAccess)
|
||||
return testCommandExecute(cmd.OutOrStdout(), dirPath, fileName, gitBranch, testCase, failOnly, detailedResults)
|
||||
},
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/log"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/pluralize"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/path"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/processor"
|
||||
|
@ -17,6 +16,7 @@ import (
|
|||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/userinfo"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/variables"
|
||||
"github.com/kyverno/kyverno/ext/output/pluralize"
|
||||
"github.com/kyverno/kyverno/pkg/autogen"
|
||||
"github.com/kyverno/kyverno/pkg/background/generate"
|
||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||
|
|
|
@ -3,30 +3,17 @@ package color
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/kataras/tablewriter"
|
||||
"github.com/kyverno/kyverno/ext/output/color"
|
||||
)
|
||||
|
||||
var (
|
||||
BoldGreen *color.Color
|
||||
BoldRed *color.Color
|
||||
BoldYellow *color.Color
|
||||
BoldFgCyan *color.Color
|
||||
HeaderBgColor int
|
||||
HeaderFgColor int
|
||||
)
|
||||
|
||||
func InitColors(noColor bool) {
|
||||
toggleColor := func(c *color.Color) *color.Color {
|
||||
if noColor {
|
||||
c.DisableColor()
|
||||
}
|
||||
return c
|
||||
}
|
||||
BoldGreen = toggleColor(color.New(color.FgGreen).Add(color.Bold))
|
||||
BoldRed = toggleColor(color.New(color.FgRed).Add(color.Bold))
|
||||
BoldYellow = toggleColor(color.New(color.FgYellow).Add(color.Bold))
|
||||
BoldFgCyan = toggleColor(color.New(color.FgCyan).Add(color.Bold))
|
||||
func Init(noColor bool) {
|
||||
color.Init(noColor)
|
||||
if !noColor {
|
||||
HeaderBgColor = tablewriter.BgBlackColor
|
||||
HeaderFgColor = tablewriter.FgGreenColor
|
||||
|
@ -42,13 +29,13 @@ func Policy(namespace, name string) string {
|
|||
}
|
||||
}
|
||||
if namespace == "" {
|
||||
return BoldFgCyan.Sprint(name)
|
||||
return color.BoldFgCyan.Sprint(name)
|
||||
}
|
||||
return BoldFgCyan.Sprint(namespace) + "/" + BoldFgCyan.Sprint(name)
|
||||
return color.BoldFgCyan.Sprint(namespace) + "/" + color.BoldFgCyan.Sprint(name)
|
||||
}
|
||||
|
||||
func Rule(name string) string {
|
||||
return BoldFgCyan.Sprint(name)
|
||||
return color.BoldFgCyan.Sprint(name)
|
||||
}
|
||||
|
||||
func Resource(kind, namespace, name string) string {
|
||||
|
@ -60,31 +47,31 @@ func Resource(kind, namespace, name string) string {
|
|||
}
|
||||
}
|
||||
if namespace == "" {
|
||||
return BoldFgCyan.Sprint(kind) + "/" + BoldFgCyan.Sprint(name)
|
||||
return color.BoldFgCyan.Sprint(kind) + "/" + color.BoldFgCyan.Sprint(name)
|
||||
}
|
||||
return BoldFgCyan.Sprint(namespace) + "/" + BoldFgCyan.Sprint(kind) + "/" + BoldFgCyan.Sprint(name)
|
||||
return color.BoldFgCyan.Sprint(namespace) + "/" + color.BoldFgCyan.Sprint(kind) + "/" + color.BoldFgCyan.Sprint(name)
|
||||
}
|
||||
|
||||
func NotFound() string {
|
||||
return BoldYellow.Sprint("Not found")
|
||||
return color.BoldYellow.Sprint("Not found")
|
||||
}
|
||||
|
||||
func ResultPass() string {
|
||||
return BoldGreen.Sprint("Pass")
|
||||
return color.BoldGreen.Sprint("Pass")
|
||||
}
|
||||
|
||||
func ResultFail() string {
|
||||
return BoldRed.Sprint("Fail")
|
||||
return color.BoldRed.Sprint("Fail")
|
||||
}
|
||||
|
||||
func ResultWarn() string {
|
||||
return BoldYellow.Sprint("Warn")
|
||||
return color.BoldYellow.Sprint("Warn")
|
||||
}
|
||||
|
||||
func ResultError() string {
|
||||
return BoldRed.Sprint("Error")
|
||||
return color.BoldRed.Sprint("Error")
|
||||
}
|
||||
|
||||
func ResultSkip() string {
|
||||
return BoldFgCyan.Sprint("Skip")
|
||||
return color.BoldFgCyan.Sprint("Skip")
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestInitColors(t *testing.T) {
|
||||
func TestInit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
noColor bool
|
||||
|
@ -15,13 +15,13 @@ func TestInitColors(t *testing.T) {
|
|||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
InitColors(tt.noColor)
|
||||
Init(tt.noColor)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestPolicy(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
policyNamespace string
|
||||
|
@ -46,7 +46,7 @@ func TestPolicy(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRule(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
ruleName string
|
||||
|
@ -65,7 +65,7 @@ func TestRule(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResource(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
kind string
|
||||
|
@ -93,7 +93,7 @@ func TestResource(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestNotFound(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
@ -110,7 +110,7 @@ func TestNotFound(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResultPass(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
@ -127,7 +127,7 @@ func TestResultPass(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResultFail(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
@ -144,7 +144,7 @@ func TestResultFail(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResultWarn(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
@ -161,7 +161,7 @@ func TestResultWarn(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResultError(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
@ -178,7 +178,7 @@ func TestResultError(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestResultSkip(t *testing.T) {
|
||||
InitColors(true)
|
||||
Init(true)
|
||||
tests := []struct {
|
||||
name string
|
||||
want string
|
||||
|
|
25
ext/output/color/color.go
Normal file
25
ext/output/color/color.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package color
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
)
|
||||
|
||||
var (
|
||||
BoldGreen *color.Color
|
||||
BoldRed *color.Color
|
||||
BoldYellow *color.Color
|
||||
BoldFgCyan *color.Color
|
||||
)
|
||||
|
||||
func Init(noColor bool) {
|
||||
toggleColor := func(c *color.Color) *color.Color {
|
||||
if noColor {
|
||||
c.DisableColor()
|
||||
}
|
||||
return c
|
||||
}
|
||||
BoldGreen = toggleColor(color.New(color.FgGreen).Add(color.Bold))
|
||||
BoldRed = toggleColor(color.New(color.FgRed).Add(color.Bold))
|
||||
BoldYellow = toggleColor(color.New(color.FgYellow).Add(color.Bold))
|
||||
BoldFgCyan = toggleColor(color.New(color.FgCyan).Add(color.Bold))
|
||||
}
|
21
ext/output/color/color_test.go
Normal file
21
ext/output/color/color_test.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
package color
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
noColor bool
|
||||
}{{
|
||||
noColor: true,
|
||||
}, {
|
||||
noColor: false,
|
||||
}}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
Init(tt.noColor)
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue