forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_plugin_repo.go
75 lines (63 loc) · 1.91 KB
/
remove_plugin_repo.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package pluginrepo
import (
"strings"
"github.com/cloudfoundry/cli/cf/commandregistry"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/flags"
. "github.com/cloudfoundry/cli/cf/i18n"
)
type RemovePluginRepo struct {
ui terminal.UI
config coreconfig.ReadWriter
}
func init() {
commandregistry.Register(&RemovePluginRepo{})
}
func (cmd *RemovePluginRepo) MetaData() commandregistry.CommandMetadata {
return commandregistry.CommandMetadata{
Name: "remove-plugin-repo",
Description: T("Remove a plugin repository"),
Usage: []string{
T("CF_NAME remove-plugin-repo REPO_NAME"),
},
Examples: []string{
"CF_NAME remove-plugin-repo PrivateRepo",
},
TotalArgs: 1,
}
}
func (cmd *RemovePluginRepo) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) []requirements.Requirement {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + commandregistry.Commands.CommandUsage("remove-plugin-repo"))
}
reqs := []requirements.Requirement{}
return reqs
}
func (cmd *RemovePluginRepo) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command {
cmd.ui = deps.Ui
cmd.config = deps.Config
return cmd
}
func (cmd *RemovePluginRepo) Execute(c flags.FlagContext) {
cmd.ui.Say("")
repoName := strings.Trim(c.Args()[0], " ")
if i := cmd.findRepoIndex(repoName); i != -1 {
cmd.config.UnSetPluginRepo(i)
cmd.ui.Ok()
cmd.ui.Say(repoName + T(" removed from list of repositories"))
cmd.ui.Say("")
} else {
cmd.ui.Failed(repoName + T(" does not exist as a repo"))
}
}
func (cmd RemovePluginRepo) findRepoIndex(repoName string) int {
repos := cmd.config.PluginRepos()
for i, repo := range repos {
if strings.ToLower(repo.Name) == strings.ToLower(repoName) {
return i
}
}
return -1
}