github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/commands/stacks.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 ) 12 13 type ListStacks struct { 14 ui terminal.UI 15 config core_config.Reader 16 stacksRepo stacks.StackRepository 17 } 18 19 func init() { 20 command_registry.Register(&ListStacks{}) 21 } 22 23 func (cmd *ListStacks) MetaData() command_registry.CommandMetadata { 24 return command_registry.CommandMetadata{ 25 Name: "stacks", 26 Description: T("List all stacks (a stack is a pre-built file system, including an operating system, that can run apps)"), 27 Usage: T("CF_NAME stacks"), 28 } 29 } 30 31 func (cmd *ListStacks) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) (reqs []requirements.Requirement, err error) { 32 if len(fc.Args()) != 0 { 33 cmd.ui.Failed(T("Incorrect Usage. Requires app name as argument\n\n") + command_registry.Commands.CommandUsage("stacks")) 34 } 35 36 reqs = append(reqs, requirementsFactory.NewLoginRequirement()) 37 return 38 } 39 40 func (cmd *ListStacks) SetDependency(deps command_registry.Dependency, pluginCall bool) command_registry.Command { 41 cmd.ui = deps.Ui 42 cmd.config = deps.Config 43 cmd.stacksRepo = deps.RepoLocator.GetStackRepository() 44 return cmd 45 } 46 47 func (cmd *ListStacks) Execute(c flags.FlagContext) { 48 cmd.ui.Say(T("Getting stacks in org {{.OrganizationName}} / space {{.SpaceName}} as {{.Username}}...", 49 map[string]interface{}{"OrganizationName": terminal.EntityNameColor(cmd.config.OrganizationFields().Name), 50 "SpaceName": terminal.EntityNameColor(cmd.config.SpaceFields().Name), 51 "Username": terminal.EntityNameColor(cmd.config.Username())})) 52 53 stacks, apiErr := cmd.stacksRepo.FindAll() 54 if apiErr != nil { 55 cmd.ui.Failed(apiErr.Error()) 56 return 57 } 58 59 cmd.ui.Ok() 60 cmd.ui.Say("") 61 62 table := terminal.NewTable(cmd.ui, []string{T("name"), T("description")}) 63 64 for _, stack := range stacks { 65 table.Add(stack.Name, stack.Description) 66 } 67 68 table.Print() 69 }