( ctx context.Context, docID, tabID, action, target string, results []docsTableMutationResult, )
| 551 | } |
| 552 | |
| 553 | func writeDocsTableMutationResult( |
| 554 | ctx context.Context, |
| 555 | docID, tabID, action, target string, |
| 556 | results []docsTableMutationResult, |
| 557 | ) error { |
| 558 | sort.Slice(results, func(i, j int) bool { |
| 559 | return results[i].TableIndex < results[j].TableIndex |
| 560 | }) |
| 561 | if outfmt.IsJSON(ctx) { |
| 562 | payload := map[string]any{ |
| 563 | "documentId": docID, |
| 564 | "action": action, |
| 565 | "target": target, |
| 566 | "updated": true, |
| 567 | "tables": results, |
| 568 | } |
| 569 | if len(results) == 1 { |
| 570 | payload["tableIndex"] = results[0].TableIndex |
| 571 | if results[0].Index > 0 { |
| 572 | payload[target] = results[0].Index |
| 573 | } |
| 574 | if results[0].Range != "" { |
| 575 | payload["range"] = results[0].Range |
| 576 | } |
| 577 | } |
| 578 | if tabID != "" { |
| 579 | payload["tabId"] = tabID |
| 580 | } |
| 581 | return outfmt.WriteJSON(ctx, stdoutWriter(ctx), payload) |
| 582 | } |
| 583 | |
| 584 | u := ui.FromContext(ctx) |
| 585 | u.Out().Linef("documentId\t%s", docID) |
| 586 | u.Out().Linef("action\t%s", action) |
| 587 | u.Out().Linef("target\t%s", target) |
| 588 | for _, result := range results { |
| 589 | if result.Range != "" { |
| 590 | u.Out().Linef("table\t%d\t%s\t%s", result.TableIndex, target, result.Range) |
| 591 | } else { |
| 592 | u.Out().Linef("table\t%d\t%s\t%d", result.TableIndex, target, result.Index) |
| 593 | } |
| 594 | } |
| 595 | u.Out().Linef("updated\ttrue") |
| 596 | if tabID != "" { |
| 597 | u.Out().Linef("tabId\t%s", tabID) |
| 598 | } |
| 599 | return nil |
| 600 | } |
| 601 | |
| 602 | func formatDocsTableRange(startRow, startCol, endRow, endCol int) string { |
| 603 | return fmt.Sprintf("%d,%d:%d,%d", startRow, startCol, endRow, endCol) |
no test coverage detected