github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/stack.go (about) 1 package commands 2 3 import ( 4 "github.com/cloudfoundry/cli/cf/api/stacks" 5 "github.com/cloudfoundry/cli/cf/command_registry" 6 "github.com/cloudfoundry/cli/cf/configuration/core_config" 7 . "github.com/cloudfoundry/cli/cf/i18n" 8 "github.com/cloudfoundry/cli/cf/requirements" 9 "github.com/cloudfoundry/cli/cf/terminal" 10 "github.com/cloudfoundry/cli/flags" 11 "github.com/cloudfoundry/cli/flags/flag" 12 ) 13 14 type ListStack struct { 15 ui terminal.UI 16 config core_config.Reader 17 stacksRepo stacks.StackRepository 18 } 19 20 func init() { 21 command_registry.Register(&ListStack{}) 22 } 23 24 func (cmd *ListStack) MetaData() command_registry.CommandMetadata { 25 fs := make(map[string]flags.FlagSet) 26 fs["guid"] = &cliFlags.BoolFlag{Name: "guid", Usage: T("Retrieve and display the given stack's guid. All other output for the stack is suppressed.")} 27 28 return command_registry.CommandMetadata{ 29 Name: "stack", 30 Description: T("Show information for a stack (a stack is a pre-built file system, including an operating system, that can run apps)"), 31 Usage: T("CF_NAME stack STACK_NAME"), 32 Flags: fs, 33 TotalArgs: 1, 34 } 35 } 36 37 func (cmd *ListStack) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) { 38 if len(fc.Args()) != 1 { 39 cmd.ui.Failed(T("Incorrect Usage. Requires app name as argument\n\n") + command_registry.Commands.CommandUsage("auth")) 40 } 41 42 reqs = append(reqs, requirementsFactory.NewLoginRequirement()) 43 return 44 } 45 46 func (cmd *ListStack) SetDependency(deps command_registry.Dependency, _ bool) command_registry.Command { 47 cmd.ui = deps.Ui 48 cmd.config = deps.Config 49 cmd.stacksRepo = deps.RepoLocator.GetStackRepository() 50 return cmd 51 } 52 53 func (cmd *ListStack) Execute(c flags.FlagContext) { 54 stackName := c.Args()[0] 55 56 stack, apiErr := cmd.stacksRepo.FindByName(stackName) 57 58 if c.Bool("guid") { 59 cmd.ui.Say(stack.Guid) 60 } else { 61 if apiErr != nil { 62 cmd.ui.Failed(apiErr.Error()) 63 return 64 } 65 66 cmd.ui.Say(T("Getting stack '{{.Stack}}' in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...", 67 map[string]interface{}{"Stack": stackName, 68 "OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), 69 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), 70 "Username": terminal.EntityNameColor(cmd.config.Username())})) 71 72 cmd.ui.Ok() 73 cmd.ui.Say("") 74 75 table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")}) 76 table.Add(stack.Name, stack.Description) 77 table.Print() 78 } 79 }