mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Check if value is provided
This commit is contained in:
@@ -71,6 +71,11 @@ func (r *SetRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
return errors.Errorf("value should set either from flag or arg")
|
||||
}
|
||||
|
||||
// make sure that the value is provided either through values flag or as an arg
|
||||
if !valueFlagSet && len(args) < 3 {
|
||||
return errors.Errorf("value must be provided either from flag or arg")
|
||||
}
|
||||
|
||||
r.Name = args[1]
|
||||
if valueFlagSet {
|
||||
r.Value = r.Values[0]
|
||||
|
||||
@@ -603,6 +603,54 @@ spec:
|
||||
errMsg: `value should set either from flag or arg`,
|
||||
},
|
||||
|
||||
{
|
||||
name: "value must be provided from either flag or arg",
|
||||
args: []string{"replicas", "--description", "hi there"},
|
||||
inputOpenAPI: `
|
||||
apiVersion: v1alpha1
|
||||
kind: Example
|
||||
openAPI:
|
||||
definitions:
|
||||
io.k8s.cli.setters.replicas:
|
||||
description: hello world
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: me
|
||||
`,
|
||||
input: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deployment
|
||||
spec:
|
||||
replicas: 3 # {"$ref":"#/definitions/io.k8s.cli.setters.replicas"}
|
||||
`,
|
||||
expectedOpenAPI: `
|
||||
apiVersion: v1alpha1
|
||||
kind: Example
|
||||
openAPI:
|
||||
definitions:
|
||||
io.k8s.cli.setters.replicas:
|
||||
description: hello world
|
||||
x-k8s-cli:
|
||||
setter:
|
||||
name: replicas
|
||||
value: "3"
|
||||
setBy: me
|
||||
`,
|
||||
expectedResources: `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: nginx-deployment
|
||||
spec:
|
||||
replicas: 3 # {"$ref":"#/definitions/io.k8s.cli.setters.replicas"}
|
||||
`,
|
||||
errMsg: `value must be provided either from flag or arg`,
|
||||
},
|
||||
|
||||
{
|
||||
name: "openAPI list values set by flag success",
|
||||
args: []string{"list", "--values", "10", "--values", "11"},
|
||||
|
||||
Reference in New Issue
Block a user