forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_plugin_repo.go
73 lines (60 loc) · 1.86 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
package plugin_repo
import (
"strings"
"github.com/cloudfoundry/cli/cf/command_registry"
"github.com/cloudfoundry/cli/cf/configuration/core_config"
"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 core_config.ReadWriter
}
func init() {
command_registry.Register(&RemovePluginRepo{})
}
func (cmd *RemovePluginRepo) MetaData() command_registry.CommandMetadata {
return command_registry.CommandMetadata{
Name: "remove-plugin-repo",
Description: T("Remove a plugin repository"),
Usage: T(`CF_NAME remove-plugin-repo [REPO_NAME] [URL]
EXAMPLE:
cf remove-plugin-repo PrivateRepo
`),
TotalArgs: 1,
}
}
func (cmd *RemovePluginRepo) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires an argument\n\n") + command_registry.Commands.CommandUsage("remove-plugin-repo"))
}
return
}
func (cmd *RemovePluginRepo) SetDependency(deps command_registry.Dependency, pluginCall bool) command_registry.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
}