Unverified Commit ec37c0f6 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #65391 from smarterclayton/describe

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. When splitting `snake_case` words, omit the underscore While we require camelCase by convention for official APIs, CRDs may use `snake_case`, and the generic describer prints this as `Snake _ Case`. We should print `Snake Case` Prow is impacted by this for the ProwJob CRD: ``` Decoration _ Config: Gcs _ Configuration: Bucket: origin-ci-test Default _ Org: openshift Default _ Repo: origin Path _ Strategy: single Gcs _ Credentials _ Secret: gcs-publisher-credentials ``` @kubernetes/sig-cli-pr-reviews ```release-note Using `kubectl describe` on CRDs that use underscores will be prettier. ```
parents f0311d82 7ae66641
...@@ -275,19 +275,22 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte ...@@ -275,19 +275,22 @@ func printUnstructuredContent(w PrefixWriter, level int, content map[string]inte
func smartLabelFor(field string) string { func smartLabelFor(field string) string {
commonAcronyms := []string{"API", "URL", "UID", "OSB", "GUID"} commonAcronyms := []string{"API", "URL", "UID", "OSB", "GUID"}
splitted := camelcase.Split(field) parts := camelcase.Split(field)
for i := 0; i < len(splitted); i++ { result := make([]string, 0, len(parts))
part := splitted[i] for _, part := range parts {
if part == "_" {
continue
}
if slice.ContainsString(commonAcronyms, strings.ToUpper(part), nil) { if slice.ContainsString(commonAcronyms, strings.ToUpper(part), nil) {
part = strings.ToUpper(part) part = strings.ToUpper(part)
} else { } else {
part = strings.Title(part) part = strings.Title(part)
} }
splitted[i] = part result = append(result, part)
} }
return strings.Join(splitted, " ") return strings.Join(result, " ")
} }
// DefaultObjectDescriber can describe the default Kubernetes objects. // DefaultObjectDescriber can describe the default Kubernetes objects.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment