(s *schema.Schema, buffer *bytes.Buffer, resources []interface{})
| 59 | } |
| 60 | |
| 61 | func (gohanClientCLI *GohanClientCLI) createResourcesTable(s *schema.Schema, buffer *bytes.Buffer, resources []interface{}) { |
| 62 | table := tablewriter.NewWriter(buffer) |
| 63 | if len(resources) == 0 { |
| 64 | return |
| 65 | } |
| 66 | |
| 67 | include := gohanClientCLI.fieldFilter(s) |
| 68 | titles := make([]string, 0, len(s.Properties)) |
| 69 | for _, property := range s.Properties { |
| 70 | if include != nil && !include[normField(property.ID, s.ID)] { |
| 71 | continue |
| 72 | } |
| 73 | |
| 74 | titles = append(titles, property.Title) |
| 75 | } |
| 76 | table.SetHeader(titles) |
| 77 | |
| 78 | for _, rawResource := range resources { |
| 79 | resourceSlice := []string{} |
| 80 | resource := rawResource.(map[string]interface{}) |
| 81 | for _, property := range s.Properties { |
| 82 | if include != nil && !include[normField(property.ID, s.ID)] { |
| 83 | continue |
| 84 | } |
| 85 | |
| 86 | v := "" |
| 87 | if val, ok := resource[property.ID]; ok && val != nil { |
| 88 | switch property.Type { |
| 89 | case "string": |
| 90 | v = fmt.Sprint(val) |
| 91 | if property.RelationProperty != "" { |
| 92 | relatedResource, ok := resource[property.RelationProperty].(map[string]interface{}) |
| 93 | if ok { |
| 94 | v = relatedResource["name"].(string) |
| 95 | } |
| 96 | } |
| 97 | default: |
| 98 | v = fmt.Sprint(val) |
| 99 | } |
| 100 | } |
| 101 | resourceSlice = append(resourceSlice, v) |
| 102 | } |
| 103 | table.Append(resourceSlice) |
| 104 | } |
| 105 | table.Render() |
| 106 | } |
| 107 | |
| 108 | func (gohanClientCLI *GohanClientCLI) createSingleResourceTable(s *schema.Schema, buffer *bytes.Buffer, resource map[string]interface{}) { |
| 109 | include := gohanClientCLI.fieldFilter(s) |
no test coverage detected