Skip to content

Commit

Permalink
feat: add more status conditions, add extra case options for conditions
Browse files Browse the repository at this point in the history
Signed-off-by: Ilya Lesikov <[email protected]>
  • Loading branch information
ilya-lesikov committed Dec 18, 2023
1 parent f7bed28 commit 969cad9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ 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
github.com/samber/lo v1.38.1
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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
33 changes: 20 additions & 13 deletions pkg/tracker/generic/resource_state_json_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -64,11 +64,14 @@ func buildUniversalConditions() {
"creating",
"updating",
"waiting",
"awaiting",
"pending",
"finishing",
"starting",
"readying",
"in progress",
"progressing",
"initialization",
"initializing",
"approving",
"unknown",
Expand Down Expand Up @@ -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
}

0 comments on commit 969cad9

Please sign in to comment.