(ctx context.Context, flags *RootFlags)
| 69 | } |
| 70 | |
| 71 | func (c *DocsInsertImageCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 72 | docID := strings.TrimSpace(c.DocID) |
| 73 | if docID == "" { |
| 74 | return usage("empty docId") |
| 75 | } |
| 76 | if c.Width < 0 || c.Height < 0 { |
| 77 | return usage("--width and --height must be non-negative") |
| 78 | } |
| 79 | source, err := c.resolveSource() |
| 80 | if err != nil { |
| 81 | return err |
| 82 | } |
| 83 | target, err := c.resolveTarget() |
| 84 | if err != nil { |
| 85 | return err |
| 86 | } |
| 87 | dryRunPayload := map[string]any{ |
| 88 | "documentId": docID, |
| 89 | "width": c.Width, |
| 90 | "height": c.Height, |
| 91 | "tab": c.Tab, |
| 92 | string(target.mode): target.anchor, |
| 93 | } |
| 94 | if source.imageURL != "" { |
| 95 | dryRunPayload["url"] = source.imageURL |
| 96 | } else { |
| 97 | dryRunPayload["file"] = source.localPath |
| 98 | dryRunPayload["name"] = source.name |
| 99 | dryRunPayload["mimeType"] = source.mimeType |
| 100 | dryRunPayload["parent"] = c.Parent |
| 101 | dryRunPayload["onRestricted"] = c.OnRestricted |
| 102 | } |
| 103 | if dryRunErr := dryRunExit(ctx, flags, "docs.insert-image", dryRunPayload); dryRunErr != nil { |
| 104 | return dryRunErr |
| 105 | } |
| 106 | if source.imageURL == "" { |
| 107 | if confirmErr := confirmDestructiveChecked(ctx, flagsWithoutDryRun(flags), fmt.Sprintf("temporarily share uploaded image %s with anyone (public) so Google Docs can fetch it", source.name)); confirmErr != nil { |
| 108 | return confirmErr |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | account, err := requireAccount(flags) |
| 113 | if err != nil { |
| 114 | return err |
| 115 | } |
| 116 | docsSvc, err := docsService(ctx, account) |
| 117 | if err != nil { |
| 118 | return err |
| 119 | } |
| 120 | |
| 121 | var result docsInsertImageResult |
| 122 | if source.imageURL != "" { |
| 123 | result, err = c.runURL(ctx, docsSvc, docID, source.imageURL, target) |
| 124 | } else { |
| 125 | driveSvc, driveErr := driveService(ctx, account) |
| 126 | if driveErr != nil { |
| 127 | return driveErr |
| 128 | } |
nothing calls this directly
no test coverage detected