github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/cf/actors/plugininstaller/plugin_installer.go (about)

     1  package plugininstaller
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/actors/pluginrepo"
     5  	"code.cloudfoundry.org/cli/cf/models"
     6  	"code.cloudfoundry.org/cli/cf/terminal"
     7  	"code.cloudfoundry.org/cli/util"
     8  	"code.cloudfoundry.org/cli/util/downloader"
     9  )
    10  
    11  //go:generate counterfeiter . PluginInstaller
    12  
    13  type PluginInstaller interface {
    14  	Install(inputSourceFilepath string) string
    15  }
    16  
    17  type Context struct {
    18  	Checksummer    util.Sha1Checksum
    19  	FileDownloader downloader.Downloader
    20  	GetPluginRepos pluginReposFetcher
    21  	PluginRepo     pluginrepo.PluginRepo
    22  	RepoName       string
    23  	UI             terminal.UI
    24  }
    25  
    26  type pluginReposFetcher func() []models.PluginRepo
    27  
    28  func NewPluginInstaller(context *Context) PluginInstaller {
    29  	var installer PluginInstaller
    30  
    31  	pluginDownloader := &PluginDownloader{UI: context.UI, FileDownloader: context.FileDownloader}
    32  	if context.RepoName == "" {
    33  		installer = &pluginInstallerWithoutRepo{
    34  			UI:               context.UI,
    35  			PluginDownloader: pluginDownloader,
    36  			RepoName:         context.RepoName,
    37  		}
    38  	} else {
    39  		installer = &pluginInstallerWithRepo{
    40  			UI:               context.UI,
    41  			PluginDownloader: pluginDownloader,
    42  			RepoName:         context.RepoName,
    43  			Checksummer:      context.Checksummer,
    44  			PluginRepo:       context.PluginRepo,
    45  			GetPluginRepos:   context.GetPluginRepos,
    46  		}
    47  	}
    48  	return installer
    49  }