MCPcopy Index your code
hub / github.com/cloudfoundry/cli / displayTable

Method displayTable

command/v7/stacks_command.go:48–84  ·  view source on GitHub ↗
(stacks []resources.Stack)

Source from the content-addressed store, hash-verified

46}
47
48func (cmd StacksCommand) displayTable(stacks []resources.Stack) {
49 if len(stacks) > 0 {
50 // Check if any stack has a state value
51 hasState := false
52 for _, stack := range stacks {
53 if stack.State != "" {
54 hasState = true
55 break
56 }
57 }
58
59 // Build the header based on whether state is present
60 var keyValueTable [][]string
61 if hasState {
62 keyValueTable = [][]string{
63 {"name", "description", "state"},
64 }
65 } else {
66 keyValueTable = [][]string{
67 {"name", "description"},
68 }
69 }
70
71 // Build the rows
72 for _, stack := range stacks {
73 if hasState {
74 keyValueTable = append(keyValueTable, []string{stack.Name, stack.Description, stack.State})
75 } else {
76 keyValueTable = append(keyValueTable, []string{stack.Name, stack.Description})
77 }
78 }
79
80 cmd.UI.DisplayTableWithHeader("", keyValueTable, ui.DefaultTableSpacePadding)
81 } else {
82 cmd.UI.DisplayText("No stacks found.")
83 }
84}

Callers 1

ExecuteMethod · 0.95

Calls 2

DisplayTextMethod · 0.65

Tested by

no test coverage detected