1/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package add
18
19import (
20	"github.com/spf13/cobra"
21	"sigs.k8s.io/kustomize/pkg/fs"
22	"sigs.k8s.io/kustomize/pkg/ifc"
23)
24
25// NewCmdAdd returns an instance of 'add' subcommand.
26func NewCmdAdd(fsys fs.FileSystem, v ifc.Validator, kf ifc.KunstructuredFactory) *cobra.Command {
27	c := &cobra.Command{
28		Use:   "add",
29		Short: "Adds an item to the kustomization file.",
30		Long:  "",
31		Example: `
32	# Adds a secret to the kustomization file
33	kustomize edit add secret NAME --from-literal=k=v
34
35	# Adds a configmap to the kustomization file
36	kustomize edit add configmap NAME --from-literal=k=v
37
38	# Adds a resource to the kustomization
39	kustomize edit add resource <filepath>
40
41	# Adds a patch to the kustomization
42	kustomize edit add patch <filepath>
43
44	# Adds one or more base directories to the kustomization
45	kustomize edit add base <filepath>
46	kustomize edit add base <filepath1>,<filepath2>,<filepath3>
47
48	# Adds one or more commonLabels to the kustomization
49	kustomize edit add label {labelKey1:labelValue1},{labelKey2:labelValue2}
50
51	# Adds one or more commonAnnotations to the kustomization
52	kustomize edit add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}
53`,
54		Args: cobra.MinimumNArgs(1),
55	}
56	c.AddCommand(
57		newCmdAddResource(fsys),
58		newCmdAddPatch(fsys),
59		newCmdAddSecret(fsys, kf),
60		newCmdAddConfigMap(fsys, kf),
61		newCmdAddBase(fsys),
62		newCmdAddLabel(fsys, v.MakeLabelValidator()),
63		newCmdAddAnnotation(fsys, v.MakeAnnotationValidator()),
64	)
65	return c
66}
67