(ctx context.Context, flags *RootFlags, batchID, documentID, command, revisionID string, requests []*docs.Request, requireEmpty bool)
| 427 | } |
| 428 | |
| 429 | func queueDocsBatchRequests(ctx context.Context, flags *RootFlags, batchID, documentID, command, revisionID string, requests []*docs.Request, requireEmpty bool) (bool, error) { |
| 430 | batchID = strings.TrimSpace(batchID) |
| 431 | if batchID == "" { |
| 432 | return false, nil |
| 433 | } |
| 434 | if err := validateDocsBatchIDArg(batchID); err != nil { |
| 435 | return true, err |
| 436 | } |
| 437 | if len(requests) == 0 { |
| 438 | return true, errors.New("no Docs requests to append") |
| 439 | } |
| 440 | account, err := requireAccount(flags) |
| 441 | if err != nil { |
| 442 | return true, err |
| 443 | } |
| 444 | client, err := resolveClientForEmail(ctx, account, flags) |
| 445 | if err != nil { |
| 446 | return true, err |
| 447 | } |
| 448 | store, err := newDocsBatchStore(ctx) |
| 449 | if err != nil { |
| 450 | return true, err |
| 451 | } |
| 452 | rawRequests, err := marshalDocsBatchRequests(requests) |
| 453 | if err != nil { |
| 454 | return true, err |
| 455 | } |
| 456 | total, err := store.Append(docsbatch.AppendOptions{ |
| 457 | BatchID: batchID, |
| 458 | Command: command, |
| 459 | Identity: docsbatch.Identity{ |
| 460 | Service: docsbatch.ServiceDocs, |
| 461 | DocumentID: documentID, |
| 462 | Account: account, |
| 463 | Client: client, |
| 464 | }, |
| 465 | RevisionID: revisionID, |
| 466 | Requests: rawRequests, |
| 467 | RequireEmpty: requireEmpty, |
| 468 | }) |
| 469 | if err != nil { |
| 470 | return true, err |
| 471 | } |
| 472 | if outfmt.IsJSON(ctx) { |
| 473 | err = outfmt.WriteJSON(ctx, stdoutWriter(ctx), map[string]any{ |
| 474 | "batch_id": batchID, |
| 475 | "queued": len(requests), |
| 476 | "requests": total, |
| 477 | }) |
| 478 | } else { |
| 479 | out := ui.FromContext(ctx).Out() |
| 480 | out.Linef("batch_id\t%s", batchID) |
| 481 | out.Linef("queued\t%d", len(requests)) |
| 482 | out.Linef("requests\t%d", total) |
| 483 | } |
| 484 | |
| 485 | return true, err |
| 486 | } |
no test coverage detected