diff --git a/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext.tmpl b/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext.tmpl index 464a6986270..971dfff1f22 100644 --- a/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext.tmpl +++ b/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext.tmpl @@ -110,7 +110,7 @@ Takes dictionary as argument with keys: {{- if eq 1 (len $.FieldPath) -}} {{- /* TODO: The original explain would say RESOURCE instead of FIELD here under some circumstances */ -}} FIELD: {{first $.FieldPath}} <{{ template "typeGuess" (dict "schema" $subschema "Document" $.Document) }}>{{"\n"}} - {{- template "extractEnum" (dict "schema" $subschema "Document" $.Document "longFormView" false "limit" 3) -}}{{"\n"}} + {{- template "extractEnum" (dict "schema" $subschema "Document" $.Document "isLongView" true "limit" -1) -}}{{"\n"}} {{- "\n" -}} {{- end -}} @@ -205,7 +205,7 @@ Takes dictionary as argument with keys: {{- $fieldSchema := index $.schema.properties $.name -}} {{- $.name | indent $indentAmount -}}{{"\t"}}<{{ template "typeGuess" (dict "schema" $fieldSchema "Document" $.Document) }}> {{- if contains $.schema.required $.name}} -required-{{- end -}} - {{- template "extractEnum" (dict "schema" $fieldSchema "Document" $.Document "longFormView" true "limit" -1 "indentAmount" $indentAmount) -}} + {{- template "extractEnum" (dict "schema" $fieldSchema "Document" $.Document "isLongView" false "limit" 4 "indentAmount" $indentAmount) -}} {{- "\n" -}} {{- if not $.short -}} {{- or $fieldSchema.description "" | wrap (sub 78 $indentAmount) | indent (add $indentAmount 2) -}}{{- "\n" -}} @@ -295,7 +295,7 @@ Takes dictionary as argument with keys: Takes dictionary as argument with keys: schema: openapiv3 JSON schema Document: openapi document - longFormView: (boolean) prints the enums in extended long form view or not + isLongView: (boolean) Simple view: long list of all fields. Long view: all details of one field limit: (int) truncate the amount of enums that can be printed in simple view, -1 means all items indentAmount: intent of the beginning enum line in longform view */ -}} @@ -304,22 +304,30 @@ Takes dictionary as argument with keys: {{- if .enum -}} {{- $enumLen := len .enum -}} {{- $limit := or $.limit -1 -}} - {{- if $.longFormView -}} + {{- if eq $.isLongView false -}} {{- "\n" -}} {{- "" | indent $.indentAmount -}} {{- "enum: " -}} {{- else -}} - {{- "ENUM: " -}} + {{- "ENUM:" -}} {{- end -}} {{- range $index, $element := .enum -}} + {{- /* Prints , .... and return the range when it goes over the limit */ -}} {{- if and (gt $limit -1) (ge $index $limit) -}} - {{- /* Prints ,.. and return the range when it goes over the limit */ -}} - {{- ",.." -}} + {{- ", ...." -}} {{- break -}} {{- end -}} {{- /* Use to reflect "" when we see empty string */ -}} {{- $elementType := printf "%T" $element -}} - {{- if gt $index 0 -}} {{- ", " -}} {{- end -}} + {{- /* Print out either `, ` or `\n ` based of the view */ -}} + {{- /* Simple view */ -}} + {{- if and (gt $index 0) (eq $.isLongView false) -}} + {{- ", " -}} + {{- /* Long view */ -}} + {{- else if eq $.isLongView true -}} + {{- "\n" -}}{{- "" | indent 4 -}} + {{- end -}} + {{- /* Convert empty string to `""` for more clarification */ -}} {{- if and (eq "string" $elementType) (eq $element "") -}} {{- `""` -}} {{- else -}} diff --git a/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext_test.go b/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext_test.go index 46af394b7bf..f209d488ce0 100644 --- a/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext_test.go +++ b/staging/src/k8s.io/kubectl/pkg/explain/v2/templates/plaintext_test.go @@ -673,10 +673,10 @@ func TestPlaintext(t *testing.T) { "description": "a description that should not be printed", "enum": []any{0, 1, 2, 3}, }, - "longFormView": false, + "isLongView": true, }, Checks: []check{ - checkEquals("ENUM: 0, 1, 2, 3"), + checkEquals("ENUM:\n 0\n 1\n 2\n 3"), }, }, { @@ -689,7 +689,7 @@ func TestPlaintext(t *testing.T) { "description": "a description that should not be printed", "enum": []any{0, 1, 2, 3}, }, - "longFormView": true, + "isLongView": false, "indentAmount": 2, }, Checks: []check{ @@ -706,12 +706,12 @@ func TestPlaintext(t *testing.T) { "description": "a description that should not be printed", "enum": []any{0, 1, 2, 3}, }, - "longFormView": true, + "isLongView": false, "limit": 2, "indentAmount": 2, }, Checks: []check{ - checkEquals("\n enum: 0, 1,.."), + checkEquals("\n enum: 0, 1, ...."), }, }, { @@ -724,12 +724,12 @@ func TestPlaintext(t *testing.T) { "description": "a description that should not be printed", "enum": []any{0, 1, 2, 3}, }, - "longFormView": false, + "isLongView": true, "limit": 2, "indentAmount": 2, }, Checks: []check{ - checkEquals("ENUM: 0, 1,.."), + checkEquals("ENUM:\n 0\n 1, ...."), }, }, { @@ -742,10 +742,10 @@ func TestPlaintext(t *testing.T) { "description": "a description that should not be printed", "enum": []any{"Block", "File", ""}, }, - "longFormView": false, + "isLongView": true, }, Checks: []check{ - checkEquals("ENUM: Block, File, \"\""), + checkEquals("ENUM:\n Block\n File\n \"\""), }, }, }