Hide list-subst behind a flag

This commit is contained in:
Phani Teja Marupaka
2020-07-03 23:55:29 -07:00
parent a7545bdad3
commit c12e95fe06
2 changed files with 24 additions and 11 deletions

View File

@@ -32,6 +32,8 @@ func NewListSettersRunner(parent string) *ListSettersRunner {
} }
c.Flags().BoolVar(&r.Markdown, "markdown", false, c.Flags().BoolVar(&r.Markdown, "markdown", false,
"output as github markdown") "output as github markdown")
c.Flags().BoolVar(&r.IncludeSubst, "include-subst", false,
"include substitutions in the output")
fixDocs(parent, c) fixDocs(parent, c)
r.Command = c r.Command = c
return r return r
@@ -42,10 +44,11 @@ func ListSettersCommand(parent string) *cobra.Command {
} }
type ListSettersRunner struct { type ListSettersRunner struct {
Command *cobra.Command Command *cobra.Command
Lookup setters.LookupSetters Lookup setters.LookupSetters
List setters2.List List setters2.List
Markdown bool Markdown bool
IncludeSubst bool
} }
func (r *ListSettersRunner) preRunE(c *cobra.Command, args []string) error { func (r *ListSettersRunner) preRunE(c *cobra.Command, args []string) error {
@@ -63,7 +66,10 @@ func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error {
if err := r.ListSetters(c, args); err != nil { if err := r.ListSetters(c, args); err != nil {
return err return err
} }
return r.ListSubstitutions(c, args) if r.IncludeSubst {
return r.ListSubstitutions(c, args)
}
return nil
} }
return handleError(c, lookup(r.Lookup, c, args)) return handleError(c, lookup(r.Lookup, c, args))
@@ -119,6 +125,9 @@ func (r *ListSettersRunner) ListSubstitutions(c *cobra.Command, args []string) e
return err return err
} }
table := newTable(c.OutOrStdout(), r.Markdown) table := newTable(c.OutOrStdout(), r.Markdown)
b := tablewriter.Border{Top: true}
table.SetBorders(b)
table.SetHeader([]string{"SUBSTITUTION", "PATTERN", "REFERENCES"}) table.SetHeader([]string{"SUBSTITUTION", "PATTERN", "REFERENCES"})
for i := range r.List.Substitutions { for i := range r.List.Substitutions {
s := r.List.Substitutions[i] s := r.List.Substitutions[i]

View File

@@ -78,6 +78,7 @@ spec:
}, },
{ {
name: "list-multiple", name: "list-multiple",
args: []string{"--include-subst"},
openapi: ` openapi: `
openAPI: openAPI:
definitions: definitions:
@@ -134,12 +135,14 @@ spec:
image nginx me2 hello world 2 2 No image nginx me2 hello world 2 2 No
replicas 3 me1 hello world 1 1 No replicas 3 me1 hello world 1 1 No
tag 1.7.9 me3 hello world 3 1 Yes tag 1.7.9 me3 hello world 3 1 Yes
--------------- ----------- --------------
SUBSTITUTION PATTERN REFERENCES SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag] image IMAGE:TAG [image,tag]
`, `,
}, },
{ {
name: "list-multiple-resources", name: "list-multiple-resources",
args: []string{"--include-subst"},
openapi: ` openapi: `
openAPI: openAPI:
definitions: definitions:
@@ -208,6 +211,7 @@ spec:
image nginx me2 hello world 2 3 No image nginx me2 hello world 2 3 No
replicas 3 me1 hello world 1 2 No replicas 3 me1 hello world 1 2 No
tag 1.7.9 me3 hello world 3 2 No tag 1.7.9 me3 hello world 3 2 No
--------------- ----------- --------------
SUBSTITUTION PATTERN REFERENCES SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag] image IMAGE:TAG [image,tag]
`, `,
@@ -240,10 +244,10 @@ openAPI:
name: tag name: tag
value: "1.7.9" value: "1.7.9"
setBy: me3 setBy: me3
io.k8s.cli.substitutions.image: io.k8s.cli.substitutions.image-subst:
x-k8s-cli: x-k8s-cli:
substitution: substitution:
name: image name: image-subst
pattern: IMAGE:TAG pattern: IMAGE:TAG
values: values:
- marker: IMAGE - marker: IMAGE
@@ -262,7 +266,7 @@ spec:
spec: spec:
containers: containers:
- name: nginx - name: nginx
image: nginx:1.7.9 # {"$ref": "#/definitions/io.k8s.cli.substitutions.image"} image: nginx:1.7.9 # {"$ref": "#/definitions/io.k8s.cli.substitutions.image-subst"}
- name: nginx2 - name: nginx2
image: nginx # {"$ref": "#/definitions/io.k8s.cli.setters.image"} image: nginx # {"$ref": "#/definitions/io.k8s.cli.setters.image"}
--- ---
@@ -276,14 +280,12 @@ spec:
spec: spec:
containers: containers:
- name: nginx - name: nginx
image: nginx:1.7.9 # {"$ref": "#/definitions/io.k8s.cli.substitutions.image"} image: nginx:1.7.9 # {"$ref": "#/definitions/io.k8s.cli.substitutions.image-subst"}
- name: nginx2 - name: nginx2
image: nginx image: nginx
`, `,
expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED expected: ` NAME VALUE SET BY DESCRIPTION COUNT REQUIRED
image nginx me2 hello world 2 3 Yes image nginx me2 hello world 2 3 Yes
SUBSTITUTION PATTERN REFERENCES
image IMAGE:TAG [image,tag]
`, `,
}, },
@@ -329,6 +331,7 @@ spec:
{ {
name: "nested substitution", name: "nested substitution",
args: []string{"--include-subst"},
input: ` input: `
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
@@ -391,6 +394,7 @@ openAPI:
my-image-setter nginx 2 No my-image-setter nginx 2 No
my-other-setter nginxotherthing 1 No my-other-setter nginxotherthing 1 No
my-tag-setter 1.7.9 2 Yes my-tag-setter 1.7.9 2 Yes
------------------ ------------------------------------------------ -----------------------------------
SUBSTITUTION PATTERN REFERENCES SUBSTITUTION PATTERN REFERENCES
my-image-subst ${my-image-setter}::${my-tag-setter} [my-image-setter,my-tag-setter] my-image-subst ${my-image-setter}::${my-tag-setter} [my-image-setter,my-tag-setter]
my-nested-subst something/${my-image-subst}/${my-other-setter} [my-image-subst,my-other-setter] my-nested-subst something/${my-image-subst}/${my-other-setter} [my-image-subst,my-other-setter]