(stacks []resources.Stack)
| 46 | } |
| 47 | |
| 48 | func (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 | } |
no test coverage detected