github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/cf/actors/plugininstaller/plugin_installer_without_repo.go (about) 1 package plugininstaller 2 3 import ( 4 "os" 5 "path/filepath" 6 "strings" 7 8 . "code.cloudfoundry.org/cli/cf/i18n" 9 "code.cloudfoundry.org/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 }