forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
71 lines (61 loc) · 2.28 KB
/
service.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
package service
import (
"github.com/cloudfoundry/cli/cf/command_metadata"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/codegangsta/cli"
)
type ShowService struct {
ui terminal.UI
serviceInstanceReq requirements.ServiceInstanceRequirement
}
func NewShowService(ui terminal.UI) (cmd *ShowService) {
cmd = new(ShowService)
cmd.ui = ui
return
}
func (cmd *ShowService) Metadata() command_metadata.CommandMetadata {
return command_metadata.CommandMetadata{
Name: "service",
Description: T("Show service instance info"),
Usage: T("CF_NAME service SERVICE_INSTANCE"),
}
}
func (cmd *ShowService) GetRequirements(requirementsFactory requirements.Factory, c *cli.Context) (reqs []requirements.Requirement, err error) {
if len(c.Args()) != 1 {
cmd.ui.FailWithUsage(c)
}
cmd.serviceInstanceReq = requirementsFactory.NewServiceInstanceRequirement(c.Args()[0])
reqs = []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
requirementsFactory.NewTargetedSpaceRequirement(),
cmd.serviceInstanceReq,
}
return
}
func (cmd *ShowService) Run(c *cli.Context) {
serviceInstance := cmd.serviceInstanceReq.GetServiceInstance()
cmd.ui.Say("")
cmd.ui.Say(T("Service instance: {{.ServiceName}}", map[string]interface{}{"ServiceName": terminal.EntityNameColor(serviceInstance.Name)}))
if serviceInstance.IsUserProvided() {
cmd.ui.Say(T("Service: {{.ServiceDescription}}",
map[string]interface{}{
"ServiceDescription": terminal.EntityNameColor(T("user-provided")),
}))
} else {
cmd.ui.Say(T("Service: {{.ServiceDescription}}",
map[string]interface{}{
"ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Label),
}))
cmd.ui.Say(T("Plan: {{.ServicePlanName}}",
map[string]interface{}{
"ServicePlanName": terminal.EntityNameColor(serviceInstance.ServicePlan.Name),
}))
cmd.ui.Say(T("Description: {{.ServiceDescription}}", map[string]interface{}{"ServiceDescription": terminal.EntityNameColor(serviceInstance.ServiceOffering.Description)}))
cmd.ui.Say(T("Documentation url: {{.URL}}",
map[string]interface{}{
"URL": terminal.EntityNameColor(serviceInstance.ServiceOffering.DocumentationUrl),
}))
}
}