github.com/aaronmell/helm@v3.0.0-beta.2+incompatible/cmd/helm/root.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 // import "helm.sh/helm/cmd/helm" 18 19 import ( 20 "io" 21 22 "github.com/spf13/cobra" 23 24 "helm.sh/helm/cmd/helm/require" 25 "helm.sh/helm/internal/experimental/registry" 26 "helm.sh/helm/pkg/action" 27 ) 28 29 const ( 30 bashCompletionFunc = ` 31 __helm_override_flag_list=(--kubeconfig --kube-context --home --namespace -n) 32 __helm_override_flags() 33 { 34 local ${__helm_override_flag_list[*]##*-} two_word_of of var 35 for w in "${words[@]}"; do 36 if [ -n "${two_word_of}" ]; then 37 eval "${two_word_of##*-}=\"${two_word_of}=\${w}\"" 38 two_word_of= 39 continue 40 fi 41 for of in "${__helm_override_flag_list[@]}"; do 42 case "${w}" in 43 ${of}=*) 44 eval "${of##*-}=\"${w}\"" 45 ;; 46 ${of}) 47 two_word_of="${of}" 48 ;; 49 esac 50 done 51 done 52 for var in "${__helm_override_flag_list[@]##*-}"; do 53 if eval "test -n \"\$${var}\""; then 54 eval "echo \${${var}}" 55 fi 56 done 57 } 58 __helm_list_releases() 59 { 60 __helm_debug "${FUNCNAME[0]}: c is $c words[c] is ${words[c]}" 61 local out filter 62 # Use ^ to map from the start of the release name 63 filter="^${words[c]}" 64 if out=$(helm list $(__helm_override_flags) -a -q -m 1000 -f ${filter} 2>/dev/null); then 65 COMPREPLY=( $( compgen -W "${out[*]}" -- "$cur" ) ) 66 fi 67 } 68 __helm_custom_func() 69 { 70 __helm_debug "${FUNCNAME[0]}: last_command is $last_command" 71 case ${last_command} in 72 helm_uninstall | helm_history | helm_status | helm_test_run |\ 73 helm_upgrade | helm_rollback | helm_get_*) 74 __helm_list_releases 75 return 76 ;; 77 *) 78 ;; 79 esac 80 } 81 ` 82 ) 83 84 var globalUsage = `The Kubernetes package manager 85 86 Common actions for Helm: 87 88 - helm search: search for charts 89 - helm fetch: download a chart to your local directory to view 90 - helm install: upload the chart to Kubernetes 91 - helm list: list releases of charts 92 93 Environment: 94 $XDG_CACHE_HOME set an alternative location for storing cached files. 95 $XDG_CONFIG_HOME set an alternative location for storing Helm configuration. 96 $XDG_DATA_HOME set an alternative location for storing Helm data. 97 $HELM_DRIVER set the backend storage driver. Values are: configmap, secret, memory 98 $HELM_NO_PLUGINS disable plugins. Set HELM_NO_PLUGINS=1 to disable plugins. 99 $KUBECONFIG set an alternative Kubernetes configuration file (default "~/.kube/config") 100 ` 101 102 func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string) *cobra.Command { 103 cmd := &cobra.Command{ 104 Use: "helm", 105 Short: "The Helm package manager for Kubernetes.", 106 Long: globalUsage, 107 SilenceUsage: true, 108 Args: require.NoArgs, 109 BashCompletionFunction: bashCompletionFunc, 110 } 111 flags := cmd.PersistentFlags() 112 113 settings.AddFlags(flags) 114 115 // We can safely ignore any errors that flags.Parse encounters since 116 // those errors will be caught later during the call to cmd.Execution. 117 // This call is required to gather configuration information prior to 118 // execution. 119 flags.ParseErrorsWhitelist.UnknownFlags = true 120 flags.Parse(args) 121 122 // set defaults from environment 123 settings.Init(flags) 124 125 // Add subcommands 126 cmd.AddCommand( 127 // chart commands 128 newCreateCmd(out), 129 newDependencyCmd(out), 130 newPullCmd(out), 131 newShowCmd(out), 132 newLintCmd(out), 133 newPackageCmd(out), 134 newRepoCmd(out), 135 newSearchCmd(out), 136 newVerifyCmd(out), 137 138 // release commands 139 newGetCmd(actionConfig, out), 140 newHistoryCmd(actionConfig, out), 141 newInstallCmd(actionConfig, out), 142 newListCmd(actionConfig, out), 143 newReleaseTestCmd(actionConfig, out), 144 newRollbackCmd(actionConfig, out), 145 newStatusCmd(actionConfig, out), 146 newTemplateCmd(actionConfig, out), 147 newUninstallCmd(actionConfig, out), 148 newUpgradeCmd(actionConfig, out), 149 150 newCompletionCmd(out), 151 newPluginCmd(out), 152 newVersionCmd(out), 153 154 // Hidden documentation generator command: 'helm docs' 155 newDocsCmd(out), 156 ) 157 158 // Add *experimental* subcommands 159 registryClient, err := registry.NewClient( 160 registry.ClientOptDebug(settings.Debug), 161 registry.ClientOptWriter(out), 162 ) 163 if err != nil { 164 // TODO: dont panic here, refactor newRootCmd to return error 165 panic(err) 166 } 167 actionConfig.RegistryClient = registryClient 168 cmd.AddCommand( 169 newRegistryCmd(actionConfig, out), 170 newChartCmd(actionConfig, out), 171 ) 172 173 // Find and add plugins 174 loadPlugins(cmd, out) 175 176 return cmd 177 }