-
Notifications
You must be signed in to change notification settings - Fork 929
/
add_plugin_repo_command.go
54 lines (47 loc) · 1.88 KB
/
add_plugin_repo_command.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
48
49
50
51
52
53
54
package plugin
import (
"code.cloudfoundry.org/cli/actor/actionerror"
"code.cloudfoundry.org/cli/actor/pluginaction"
"code.cloudfoundry.org/cli/command"
"code.cloudfoundry.org/cli/command/flag"
"code.cloudfoundry.org/cli/command/plugin/shared"
)
//go:generate counterfeiter . AddPluginRepoActor
type AddPluginRepoActor interface {
AddPluginRepository(repoName string, repoURL string) error
}
type AddPluginRepoCommand struct {
RequiredArgs flag.AddPluginRepoArgs `positional-args:"yes"`
usage interface{} `usage:"CF_NAME add-plugin-repo REPO_NAME URL\n\nEXAMPLES:\n CF_NAME add-plugin-repo ExampleRepo https://example.com/repo"`
relatedCommands interface{} `related_commands:"install-plugin, list-plugin-repos"`
SkipSSLValidation bool `short:"k" hidden:"true" description:"Skip SSL certificate validation"`
UI command.UI
Config command.Config
Actor AddPluginRepoActor
}
func (cmd *AddPluginRepoCommand) Setup(config command.Config, ui command.UI) error {
cmd.UI = ui
cmd.Config = config
cmd.Actor = pluginaction.NewActor(config, shared.NewClient(config, ui, cmd.SkipSSLValidation))
return nil
}
func (cmd AddPluginRepoCommand) Execute(args []string) error {
err := cmd.Actor.AddPluginRepository(cmd.RequiredArgs.PluginRepoName, cmd.RequiredArgs.PluginRepoURL)
switch e := err.(type) {
case actionerror.RepositoryAlreadyExistsError:
cmd.UI.DisplayTextWithFlavor("{{.RepositoryURL}} already registered as {{.RepositoryName}}",
map[string]interface{}{
"RepositoryName": e.Name,
"RepositoryURL": e.URL,
})
case nil:
cmd.UI.DisplayTextWithFlavor("{{.RepositoryURL}} added as {{.RepositoryName}}",
map[string]interface{}{
"RepositoryName": cmd.RequiredArgs.PluginRepoName,
"RepositoryURL": cmd.RequiredArgs.PluginRepoURL,
})
default:
return err
}
return nil
}