github.com/amundsenjunior/helm@v2.8.0-rc.1.0.20180119233529-2b92431476e1+incompatible/cmd/helm/plugin_install.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors All rights reserved. 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 package main 17 18 import ( 19 "fmt" 20 "io" 21 22 "k8s.io/helm/pkg/helm/helmpath" 23 "k8s.io/helm/pkg/plugin" 24 "k8s.io/helm/pkg/plugin/installer" 25 26 "github.com/spf13/cobra" 27 ) 28 29 type pluginInstallCmd struct { 30 source string 31 version string 32 home helmpath.Home 33 out io.Writer 34 } 35 36 const pluginInstallDesc = ` 37 This command allows you to install a plugin from a url to a VCS repo or a local path. 38 39 Example usage: 40 $ helm plugin install https://github.com/technosophos/helm-template 41 ` 42 43 func newPluginInstallCmd(out io.Writer) *cobra.Command { 44 pcmd := &pluginInstallCmd{out: out} 45 cmd := &cobra.Command{ 46 Use: "install [options] <path|url>...", 47 Short: "install one or more Helm plugins", 48 Long: pluginInstallDesc, 49 PreRunE: func(cmd *cobra.Command, args []string) error { 50 return pcmd.complete(args) 51 }, 52 RunE: func(cmd *cobra.Command, args []string) error { 53 return pcmd.run() 54 }, 55 } 56 cmd.Flags().StringVar(&pcmd.version, "version", "", "specify a version constraint. If this is not specified, the latest version is installed") 57 return cmd 58 } 59 60 func (pcmd *pluginInstallCmd) complete(args []string) error { 61 if err := checkArgsLength(len(args), "plugin"); err != nil { 62 return err 63 } 64 pcmd.source = args[0] 65 pcmd.home = settings.Home 66 return nil 67 } 68 69 func (pcmd *pluginInstallCmd) run() error { 70 installer.Debug = settings.Debug 71 72 i, err := installer.NewForSource(pcmd.source, pcmd.version, pcmd.home) 73 if err != nil { 74 return err 75 } 76 if err := installer.Install(i); err != nil { 77 return err 78 } 79 80 debug("loading plugin from %s", i.Path()) 81 p, err := plugin.LoadDir(i.Path()) 82 if err != nil { 83 return err 84 } 85 86 if err := runHook(p, plugin.Install); err != nil { 87 return err 88 } 89 90 fmt.Fprintf(pcmd.out, "Installed plugin: %s\n", p.Metadata.Name) 91 return nil 92 }