github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/actors/plugin_installer/plugin_installer_without_repo.go (about) 1 package plugin_installer 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 8 . "github.com/cloudfoundry/cli/cf/i18n" 9 "github.com/cloudfoundry/cli/cf/terminal" 10 ) 11 12 type PluginInstallerWithoutRepo struct { 13 Ui terminal.UI 14 PluginDownloader *PluginDownloader 15 DownloadFromPath downloadFromPath 16 RepoName string 17 } 18 19 func (installer *PluginInstallerWithoutRepo) Install(inputSourceFilepath string) (outputSourceFilepath string) { 20 if filepath.Dir(inputSourceFilepath) == "." { 21 outputSourceFilepath = "./" + filepath.Clean(inputSourceFilepath) 22 } else { 23 outputSourceFilepath = inputSourceFilepath 24 } 25 26 installer.Ui.Say("") 27 if strings.HasPrefix(outputSourceFilepath, "https://") || strings.HasPrefix(outputSourceFilepath, "http://") || 28 strings.HasPrefix(outputSourceFilepath, "ftp://") || strings.HasPrefix(outputSourceFilepath, "ftps://") { 29 installer.Ui.Say(T("Attempting to download binary file from internet address...")) 30 return installer.PluginDownloader.downloadFromPath(outputSourceFilepath) 31 } else if !installer.ensureCandidatePluginBinaryExistsAtGivenPath(outputSourceFilepath) { 32 installer.Ui.Failed(T("File not found locally, make sure the file exists at given path {{.filepath}}", map[string]interface{}{"filepath": outputSourceFilepath})) 33 } 34 35 return outputSourceFilepath 36 } 37 38 func (installer *PluginInstallerWithoutRepo) ensureCandidatePluginBinaryExistsAtGivenPath(pluginSourceFilepath string) bool { 39 _, err := os.Stat(pluginSourceFilepath) 40 if err != nil && os.IsNotExist(err) { 41 return false 42 } 43 return true 44 }