github.com/stefanmcshane/helm@v0.0.0-20221213002717-88a4a2c6e77d/cmd/helm/push.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 23 "github.com/spf13/cobra" 24 25 "github.com/stefanmcshane/helm/cmd/helm/require" 26 "github.com/stefanmcshane/helm/pkg/action" 27 "github.com/stefanmcshane/helm/pkg/pusher" 28 ) 29 30 const pushDesc = ` 31 Upload a chart to a registry. 32 33 If the chart has an associated provenance file, 34 it will also be uploaded. 35 ` 36 37 func newPushCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { 38 client := action.NewPushWithOpts(action.WithPushConfig(cfg)) 39 40 cmd := &cobra.Command{ 41 Use: "push [chart] [remote]", 42 Short: "push a chart to remote", 43 Long: pushDesc, 44 Args: require.MinimumNArgs(2), 45 ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { 46 if len(args) == 0 { 47 // Do file completion for the chart file to push 48 return nil, cobra.ShellCompDirectiveDefault 49 } 50 if len(args) == 1 { 51 providers := []pusher.Provider(pusher.All(settings)) 52 var comps []string 53 for _, p := range providers { 54 for _, scheme := range p.Schemes { 55 comps = append(comps, fmt.Sprintf("%s://", scheme)) 56 } 57 } 58 return comps, cobra.ShellCompDirectiveNoFileComp | cobra.ShellCompDirectiveNoSpace 59 } 60 return nil, cobra.ShellCompDirectiveNoFileComp 61 }, 62 RunE: func(cmd *cobra.Command, args []string) error { 63 chartRef := args[0] 64 remote := args[1] 65 client.Settings = settings 66 output, err := client.Run(chartRef, remote) 67 if err != nil { 68 return err 69 } 70 fmt.Fprint(out, output) 71 return nil 72 }, 73 } 74 75 return cmd 76 }