From 969cad97bf11a1c73211c41b7133cb057334a0a5 Mon Sep 17 00:00:00 2001 From: Ilya Lesikov Date: Mon, 18 Dec 2023 21:30:15 +0300 Subject: [PATCH] feat: add more status conditions, add extra case options for conditions Signed-off-by: Ilya Lesikov --- go.mod | 3 +- go.sum | 2 ++ .../generic/resource_state_json_paths.go | 33 +++++++++++-------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 4c79d60..583b03d 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.20 require ( github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d + github.com/chanced/caps v1.0.1 github.com/dominikbraun/graph v0.23.0 github.com/fluxcd/flagger v1.29.0 github.com/gookit/color v1.5.2 @@ -11,7 +12,6 @@ require ( github.com/spf13/cobra v1.6.1 github.com/werf/logboek v0.5.5 golang.org/x/crypto v0.7.0 - golang.org/x/text v0.8.0 k8s.io/api v0.26.2 k8s.io/apimachinery v0.26.2 k8s.io/cli-runtime v0.26.2 @@ -60,6 +60,7 @@ require ( golang.org/x/oauth2 v0.5.0 // indirect golang.org/x/sys v0.6.0 // indirect golang.org/x/term v0.6.0 // indirect + golang.org/x/text v0.8.0 // indirect golang.org/x/time v0.3.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect diff --git a/go.sum b/go.sum index 3dbe0aa..e59ad6c 100644 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/avelino/slugify v0.0.0-20180501145920-855f152bd774/go.mod h1:5wi5YYOp github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/chanced/caps v1.0.1 h1:B9LhH2mmAcNjn1argkddu9fRdU+VMrfomRoeXL1DYhg= +github.com/chanced/caps v1.0.1/go.mod h1:SJhRzeYLKJ3OmzyQXhdZ7Etj7lqqWoPtQ1zcSJRtQjs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= diff --git a/pkg/tracker/generic/resource_state_json_paths.go b/pkg/tracker/generic/resource_state_json_paths.go index 732faf4..83b32de 100644 --- a/pkg/tracker/generic/resource_state_json_paths.go +++ b/pkg/tracker/generic/resource_state_json_paths.go @@ -2,10 +2,10 @@ package generic import ( "fmt" + "strings" + "github.com/chanced/caps" "github.com/samber/lo" - "golang.org/x/text/cases" - "golang.org/x/text/language" "k8s.io/apimachinery/pkg/runtime/schema" ) @@ -64,11 +64,14 @@ func buildUniversalConditions() { "creating", "updating", "waiting", + "awaiting", "pending", "finishing", "starting", "readying", + "in progress", "progressing", + "initialization", "initializing", "approving", "unknown", @@ -193,20 +196,24 @@ func buildLowPriorityConditions() { func casify(in ...string) []string { var result []string - casers := []cases.Caser{cases.Lower(language.Und), cases.Title(language.Und)} for _, value := range in { result = append(result, value) - - for _, caser := range casers { - cased := caser.String(value) - - if lo.Contains(result, cased) { - continue - } - - result = append(result, caser.String(value)) - } + result = append(result, strings.ReplaceAll(value, " ", "")) + result = append(result, caps.ToUpper(strings.ReplaceAll(value, " ", ""))) + result = append(result, caps.ToCamel(value)) + result = append(result, caps.ToKebab(value)) + result = append(result, caps.ToDotNotation(value)) + result = append(result, caps.ToSnake(value)) + result = append(result, caps.ToTitle(value)) + result = append(result, caps.ToUpper(value)) + result = append(result, caps.ToLower(value)) + result = append(result, caps.ToLowerCamel(value)) + result = append(result, caps.ToScreamingDotNotation(value)) + result = append(result, caps.ToScreamingKebab(value)) + result = append(result, caps.ToScreamingSnake(value)) } + result = lo.Uniq(result) + return result }