(ctx context.Context, flags *RootFlags, action string, loc docsInsertLocationFlags, payload map[string]any)
| 262 | } |
| 263 | |
| 264 | func dryRunDocsSingleInsert(ctx context.Context, flags *RootFlags, action string, loc docsInsertLocationFlags, payload map[string]any) error { |
| 265 | docID := strings.TrimSpace(loc.docID) |
| 266 | if docID == "" { |
| 267 | return usage("empty docId") |
| 268 | } |
| 269 | placement, err := planDocsInsertLocation(loc) |
| 270 | if err != nil { |
| 271 | return err |
| 272 | } |
| 273 | dryRunPayload := map[string]any{"documentId": docID, "tab": loc.tab, "batch": loc.batch} |
| 274 | for k, v := range payload { |
| 275 | dryRunPayload[k] = v |
| 276 | } |
| 277 | switch placement.Kind { |
| 278 | case docsedit.PlacementAnchor: |
| 279 | dryRunPayload["atIndex"] = docsAtIndexAnchorStart |
| 280 | addDocsAtAnchorDryRunPayload(dryRunPayload, docsAtAnchorFlags{At: placement.Anchor.Text, Occurrence: placement.Anchor.Occurrence, MatchCase: placement.Anchor.MatchCase}) |
| 281 | if loc.replaceAt { |
| 282 | dryRunPayload["replaceAt"] = true |
| 283 | } |
| 284 | case docsedit.PlacementEnd: |
| 285 | dryRunPayload["atIndex"] = docsAtIndexEnd |
| 286 | case docsedit.PlacementIndex: |
| 287 | dryRunPayload["atIndex"] = placement.Index |
| 288 | } |
| 289 | return dryRunExit(ctx, flags, action, dryRunPayload) |
| 290 | } |
| 291 | |
| 292 | func planDocsInsertLocation(loc docsInsertLocationFlags) (docsedit.Placement, error) { |
| 293 | placement, err := docsedit.PlanEndInsertPlacement(docsedit.EndInsertPlacementOptions{ |
no test coverage detected