forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugins.go
60 lines (49 loc) · 1.47 KB
/
plugins.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
package plugin
import (
"github.com/cloudfoundry/cli/cf/command_metadata"
"github.com/cloudfoundry/cli/cf/configuration/plugin_config"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/codegangsta/cli"
)
type Plugins struct {
ui terminal.UI
config plugin_config.PluginConfiguration
}
func NewPlugins(ui terminal.UI, config plugin_config.PluginConfiguration) *Plugins {
return &Plugins{
ui: ui,
config: config,
}
}
func (cmd *Plugins) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "plugins",
Description: T("list all available plugin commands"),
Usage: T("CF_NAME plugins"),
}
}
func (cmd *Plugins) GetRequirements(_ requirements.Factory, c *cli.Context) (req []requirements.Requirement, err error) {
if len(c.Args()) != 0 {
cmd.ui.FailWithUsage(c)
}
return
}
func (cmd *Plugins) Run(c *cli.Context) {
cmd.ui.Say(T("Listing Installed Plugins..."))
plugins := cmd.config.Plugins()
table := terminal.NewTable(cmd.ui, []string{T("Plugin Name"), T("Command Name"), T("Command Help")})
for pluginName, metadata := range plugins {
for _, command := range metadata.Commands {
if command.Alias == "" {
table.Add(pluginName, command.Name, command.HelpText)
} else {
table.Add(pluginName, command.Name+", "+command.Alias, command.HelpText)
}
}
}
cmd.ui.Ok()
cmd.ui.Say("")
table.Print()
}