github.com/Racer159/jackal@v0.32.7-0.20240401174413-0bd2339e4f2e/src/cmd/tools/helm/dependency.go (about) 1 /* 2 Copyright The Helm Authors. 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 */ 15 16 /* 17 NOTICE: This file's 'package' and some functionality has been modified / removed to fit within Jackal's package structure. 18 */ 19 20 // Package helm is a copy of the main package from helm to include a subset of the helm CLI in Jackal 21 package helm 22 23 import ( 24 "io" 25 "path/filepath" 26 27 "github.com/spf13/cobra" 28 29 "helm.sh/helm/v3/cmd/helm/require" 30 "helm.sh/helm/v3/pkg/action" 31 ) 32 33 const dependencyDesc = ` 34 Manage the dependencies of a chart. 35 36 Helm charts store their dependencies in 'charts/'. For chart developers, it is 37 often easier to manage dependencies in 'Chart.yaml' which declares all 38 dependencies. 39 40 The dependency commands operate on that file, making it easy to synchronize 41 between the desired dependencies and the actual dependencies stored in the 42 'charts/' directory. 43 44 For example, this Chart.yaml declares two dependencies: 45 46 # Chart.yaml 47 dependencies: 48 - name: nginx 49 version: "1.2.3" 50 repository: "https://example.com/charts" 51 - name: memcached 52 version: "3.2.1" 53 repository: "https://another.example.com/charts" 54 55 56 The 'name' should be the name of a chart, where that name must match the name 57 in that chart's 'Chart.yaml' file. 58 59 The 'version' field should contain a semantic version or version range. 60 61 The 'repository' URL should point to a Chart Repository. Helm expects that by 62 appending '/index.yaml' to the URL, it should be able to retrieve the chart 63 repository's index. Note: 'repository' can be an alias. The alias must start 64 with 'alias:' or '@'. 65 66 Starting from 2.2.0, repository can be defined as the path to the directory of 67 the dependency charts stored locally. The path should start with a prefix of 68 "file://". For example, 69 70 # Chart.yaml 71 dependencies: 72 - name: nginx 73 version: "1.2.3" 74 repository: "file://../dependency_chart/nginx" 75 76 If the dependency chart is retrieved locally, it is not required to have the 77 repository added to helm by "helm add repo". Version matching is also supported 78 for this case. 79 ` 80 81 const dependencyListDesc = ` 82 List all of the dependencies declared in a chart. 83 84 This can take chart archives and chart directories as input. It will not alter 85 the contents of a chart. 86 87 This will produce an error if the chart cannot be loaded. 88 ` 89 90 func newDependencyCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { 91 cmd := &cobra.Command{ 92 Use: "dependency update|build|list", 93 Aliases: []string{"dep", "dependencies"}, 94 Short: "manage a chart's dependencies", 95 Long: dependencyDesc, 96 Args: require.NoArgs, 97 } 98 99 cmd.AddCommand(newDependencyListCmd(out)) 100 cmd.AddCommand(newDependencyUpdateCmd(cfg, out)) 101 cmd.AddCommand(newDependencyBuildCmd(cfg, out)) 102 103 return cmd 104 } 105 106 func newDependencyListCmd(out io.Writer) *cobra.Command { 107 client := action.NewDependency() 108 cmd := &cobra.Command{ 109 Use: "list CHART", 110 Aliases: []string{"ls"}, 111 Short: "list the dependencies for the given chart", 112 Long: dependencyListDesc, 113 Args: require.MaximumNArgs(1), 114 RunE: func(_ *cobra.Command, args []string) error { 115 chartpath := "." 116 if len(args) > 0 { 117 chartpath = filepath.Clean(args[0]) 118 } 119 return client.List(chartpath, out) 120 }, 121 } 122 123 f := cmd.Flags() 124 125 f.UintVar(&client.ColumnWidth, "max-col-width", 80, "maximum column width for output table") 126 return cmd 127 }