( ctx context.Context, docID, tabID, action, valueName string, results []docsTableRowActionResult, )
| 118 | } |
| 119 | |
| 120 | func writeDocsTableRowActionResult( |
| 121 | ctx context.Context, |
| 122 | docID, tabID, action, valueName string, |
| 123 | results []docsTableRowActionResult, |
| 124 | ) error { |
| 125 | sort.Slice(results, func(i, j int) bool { |
| 126 | return results[i].TableIndex < results[j].TableIndex |
| 127 | }) |
| 128 | tables := make([]map[string]any, 0, len(results)) |
| 129 | for _, result := range results { |
| 130 | tables = append(tables, map[string]any{"tableIndex": result.TableIndex, valueName: result.Value}) |
| 131 | } |
| 132 | if outfmt.IsJSON(ctx) { |
| 133 | payload := map[string]any{ |
| 134 | "documentId": docID, |
| 135 | "action": action, |
| 136 | "target": "row", |
| 137 | "updated": true, |
| 138 | "tables": tables, |
| 139 | } |
| 140 | if len(results) == 1 { |
| 141 | payload["tableIndex"] = results[0].TableIndex |
| 142 | payload[valueName] = results[0].Value |
| 143 | } |
| 144 | if tabID != "" { |
| 145 | payload["tabId"] = tabID |
| 146 | } |
| 147 | return outfmt.WriteJSON(ctx, stdoutWriter(ctx), payload) |
| 148 | } |
| 149 | |
| 150 | u := ui.FromContext(ctx) |
| 151 | u.Out().Linef("documentId\t%s", docID) |
| 152 | u.Out().Linef("action\t%s", action) |
| 153 | u.Out().Linef("target\trow") |
| 154 | for _, result := range results { |
| 155 | u.Out().Linef("table\t%d\t%s\t%v", result.TableIndex, valueName, result.Value) |
| 156 | } |
| 157 | u.Out().Linef("updated\ttrue") |
| 158 | if tabID != "" { |
| 159 | u.Out().Linef("tabId\t%s", tabID) |
| 160 | } |
| 161 | return nil |
| 162 | } |
no test coverage detected