-
Notifications
You must be signed in to change notification settings - Fork 929
/
uninstall_plugin_command.go
76 lines (64 loc) · 2.03 KB
/
uninstall_plugin_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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"
"code.cloudfoundry.org/cli/command/translatableerror"
)
//go:generate counterfeiter . UninstallPluginActor
type UninstallPluginActor interface {
UninstallPlugin(uninstaller pluginaction.PluginUninstaller, name string) error
}
type UninstallPluginCommand struct {
RequiredArgs flag.PluginName `positional-args:"yes"`
usage interface{} `usage:"CF_NAME uninstall-plugin PLUGIN-NAME"`
relatedCommands interface{} `related_commands:"plugins"`
Config command.Config
UI command.UI
Actor UninstallPluginActor
}
func (cmd *UninstallPluginCommand) Setup(config command.Config, ui command.UI) error {
cmd.Config = config
cmd.UI = ui
cmd.Actor = pluginaction.NewActor(config, nil)
return nil
}
func (cmd UninstallPluginCommand) Execute(args []string) error {
pluginName := cmd.RequiredArgs.PluginName
plugin, exist := cmd.Config.GetPluginCaseInsensitive(pluginName)
if !exist {
return translatableerror.PluginNotFoundError{PluginName: pluginName}
}
cmd.UI.DisplayTextWithFlavor("Uninstalling plugin {{.PluginName}}...",
map[string]interface{}{
"PluginName": plugin.Name,
})
rpcService, err := shared.NewRPCService(cmd.Config, cmd.UI)
if err != nil {
return err
}
err = cmd.Actor.UninstallPlugin(rpcService, plugin.Name)
if err != nil {
switch e := err.(type) {
case actionerror.PluginBinaryRemoveFailedError:
return translatableerror.PluginBinaryRemoveFailedError{
Err: e.Err,
}
case actionerror.PluginExecuteError:
return translatableerror.PluginBinaryUninstallError{
Err: e.Err,
}
default:
return err
}
}
cmd.UI.DisplayOK()
cmd.UI.DisplayText("Plugin {{.PluginName}} {{.PluginVersion}} successfully uninstalled.",
map[string]interface{}{
"PluginName": plugin.Name,
"PluginVersion": plugin.Version,
})
return nil
}