github.com/appscode/helm@v3.0.0-alpha.1+incompatible/cmd/helm/create.go (about) 1 /* 2 Copyright The Helm Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package main 18 19 import ( 20 "fmt" 21 "io" 22 "path/filepath" 23 24 "github.com/spf13/cobra" 25 26 "helm.sh/helm/cmd/helm/require" 27 "helm.sh/helm/pkg/chart" 28 "helm.sh/helm/pkg/chartutil" 29 ) 30 31 const createDesc = ` 32 This command creates a chart directory along with the common files and 33 directories used in a chart. 34 35 For example, 'helm create foo' will create a directory structure that looks 36 something like this: 37 38 foo/ 39 ├── .helmignore # Contains patterns to ignore when packaging Helm charts. 40 ├── Chart.yaml # Information about your chart 41 ├── values.yaml # The default values for your templates 42 ├── charts/ # Charts that this chart depends on 43 └── templates/ # The template files 44 45 'helm create' takes a path for an argument. If directories in the given path 46 do not exist, Helm will attempt to create them as it goes. If the given 47 destination exists and there are files in that directory, conflicting files 48 will be overwritten, but other files will be left alone. 49 ` 50 51 type createOptions struct { 52 starter string // --starter 53 name string 54 } 55 56 func newCreateCmd(out io.Writer) *cobra.Command { 57 o := &createOptions{} 58 59 cmd := &cobra.Command{ 60 Use: "create NAME", 61 Short: "create a new chart with the given name", 62 Long: createDesc, 63 Args: require.ExactArgs(1), 64 RunE: func(cmd *cobra.Command, args []string) error { 65 o.name = args[0] 66 return o.run(out) 67 }, 68 } 69 70 cmd.Flags().StringVarP(&o.starter, "starter", "p", "", "the named Helm starter scaffold") 71 return cmd 72 } 73 74 func (o *createOptions) run(out io.Writer) error { 75 fmt.Fprintf(out, "Creating %s\n", o.name) 76 77 chartname := filepath.Base(o.name) 78 cfile := &chart.Metadata{ 79 Name: chartname, 80 Description: "A Helm chart for Kubernetes", 81 Type: "application", 82 Version: "0.1.0", 83 AppVersion: "0.1.0", 84 APIVersion: chart.APIVersionV1, 85 } 86 87 if o.starter != "" { 88 // Create from the starter 89 lstarter := filepath.Join(settings.Home.Starters(), o.starter) 90 return chartutil.CreateFrom(cfile, filepath.Dir(o.name), lstarter) 91 } 92 93 _, err := chartutil.Create(chartname, filepath.Dir(o.name)) 94 return err 95 }