(ctx context.Context, flags *RootFlags)
| 83 | } |
| 84 | |
| 85 | func (c *DocsInsertFileChipCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 86 | fileID := strings.TrimSpace(c.FileID) |
| 87 | if fileID == "" { |
| 88 | return usage("empty --file-id") |
| 89 | } |
| 90 | loc := docsInsertLocationFlags{ |
| 91 | docID: c.DocID, |
| 92 | index: c.Index, |
| 93 | atEnd: c.AtEnd, |
| 94 | tab: c.Tab, |
| 95 | batch: c.Batch, |
| 96 | } |
| 97 | if dryRunErr := dryRunDocsSingleInsert(ctx, flags, "docs.insert-file-chip", loc, map[string]any{"fileId": fileID}); dryRunErr != nil { |
| 98 | return dryRunErr |
| 99 | } |
| 100 | if err := validateDocsBatchTarget(ctx, flags, c.Batch, c.DocID); err != nil { |
| 101 | return err |
| 102 | } |
| 103 | |
| 104 | account, err := requireAccount(flags) |
| 105 | if err != nil { |
| 106 | return err |
| 107 | } |
| 108 | driveSvc, err := driveService(ctx, account) |
| 109 | if err != nil { |
| 110 | return err |
| 111 | } |
| 112 | file, err := driveSvc.Files.Get(fileID). |
| 113 | SupportsAllDrives(true). |
| 114 | Fields("id,name,mimeType,webViewLink"). |
| 115 | Context(ctx). |
| 116 | Do() |
| 117 | if err != nil { |
| 118 | return fmt.Errorf("get Drive file: %w", err) |
| 119 | } |
| 120 | uri := file.WebViewLink |
| 121 | if uri == "" { |
| 122 | uri = bestEffortWebURL("drive", fileID) |
| 123 | } |
| 124 | req := &docs.Request{InsertRichLink: &docs.InsertRichLinkRequest{ |
| 125 | RichLinkProperties: &docs.RichLinkProperties{ |
| 126 | Uri: uri, |
| 127 | }, |
| 128 | }} |
| 129 | return runDocsSingleInsert(ctx, flags, "docs.insert-file-chip", docsInsertLocationFlags{ |
| 130 | docID: c.DocID, |
| 131 | index: c.Index, |
| 132 | atEnd: c.AtEnd, |
| 133 | tab: c.Tab, |
| 134 | batch: c.Batch, |
| 135 | }, req, map[string]any{"fileId": fileID, "title": file.Name}) |
| 136 | } |
| 137 | |
| 138 | func (c *DocsInsertDateChipCmd) Run(ctx context.Context, flags *RootFlags) error { |
| 139 | date := strings.TrimSpace(c.Date) |
nothing calls this directly
no test coverage detected