forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stack.go
82 lines (68 loc) · 2.43 KB
/
stack.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
77
78
79
80
81
82
package commands
import (
"github.com/cloudfoundry/cli/cf/api/stacks"
"github.com/cloudfoundry/cli/cf/commandregistry"
"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
. "github.com/cloudfoundry/cli/cf/i18n"
"github.com/cloudfoundry/cli/cf/requirements"
"github.com/cloudfoundry/cli/cf/terminal"
"github.com/cloudfoundry/cli/flags"
)
type ListStack struct {
ui terminal.UI
config coreconfig.Reader
stacksRepo stacks.StackRepository
}
func init() {
commandregistry.Register(&ListStack{})
}
func (cmd *ListStack) MetaData() commandregistry.CommandMetadata {
fs := make(map[string]flags.FlagSet)
fs["guid"] = &flags.BoolFlag{Name: "guid", Usage: T("Retrieve and display the given stack's guid. All other output for the stack is suppressed.")}
return commandregistry.CommandMetadata{
Name: "stack",
Description: T("Show information for a stack (a stack is a pre-built file system, including an operating system, that can run apps)"),
Usage: []string{
T("CF_NAME stack STACK_NAME"),
},
Flags: fs,
TotalArgs: 1,
}
}
func (cmd *ListStack) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) []requirements.Requirement {
if len(fc.Args()) != 1 {
cmd.ui.Failed(T("Incorrect Usage. Requires stack name as argument\n\n") + commandregistry.Commands.CommandUsage("stack"))
}
reqs := []requirements.Requirement{
requirementsFactory.NewLoginRequirement(),
}
return reqs
}
func (cmd *ListStack) SetDependency(deps commandregistry.Dependency, _ bool) commandregistry.Command {
cmd.ui = deps.UI
cmd.config = deps.Config
cmd.stacksRepo = deps.RepoLocator.GetStackRepository()
return cmd
}
func (cmd *ListStack) Execute(c flags.FlagContext) error {
stackName := c.Args()[0]
stack, err := cmd.stacksRepo.FindByName(stackName)
if c.Bool("guid") {
cmd.ui.Say(stack.GUID)
} else {
if err != nil {
return err
}
cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...",
map[string]interface{}{"Stack": stackName,
"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name),
"SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name),
"Username": terminal.EntityNameColor(cmd.config.Username())}))
cmd.ui.Ok()
cmd.ui.Say("")
table := cmd.ui.Table([]string{T("name"), T("description")})
table.Add(stack.Name, stack.Description)
table.Print()
}
return nil
}