forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_installer.go
47 lines (41 loc) · 1.32 KB
/
plugin_installer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package plugininstaller
import (
"github.com/cloudfoundry/cli/cf/actors/pluginrepo"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/downloader"
"github.com/cloudfoundry/cli/utils"
)
//go:generate counterfeiter . PluginInstaller
type PluginInstaller interface {
Install(inputSourceFilepath string) string
}
type PluginInstallerContext struct {
Checksummer utils.Sha1Checksum
FileDownloader downloader.Downloader
GetPluginRepos pluginReposFetcher
PluginRepo pluginrepo.PluginRepo
RepoName string
Ui terminal.UI
}
type pluginReposFetcher func() []models.PluginRepo
func NewPluginInstaller(context *PluginInstallerContext) (installer PluginInstaller) {
pluginDownloader := &PluginDownloader{Ui: context.Ui, FileDownloader: context.FileDownloader}
if context.RepoName == "" {
installer = &PluginInstallerWithoutRepo{
Ui: context.Ui,
PluginDownloader: pluginDownloader,
RepoName: context.RepoName,
}
} else {
installer = &PluginInstallerWithRepo{
Ui: context.Ui,
PluginDownloader: pluginDownloader,
RepoName: context.RepoName,
Checksummer: context.Checksummer,
PluginRepo: context.PluginRepo,
GetPluginRepos: context.GetPluginRepos,
}
}
return installer
}