MCPcopy Create free account
hub / github.com/openclaw/gogcli / Run

Method Run

internal/cmd/docs.go:253–338  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

251}
252
253func (c *DocsCreateCmd) Run(ctx context.Context, flags *RootFlags) error {
254 u := ui.FromContext(ctx)
255 title := strings.TrimSpace(c.Title)
256 if title == "" {
257 return usage("empty title")
258 }
259
260 f := &drive.File{
261 Name: title,
262 MimeType: "application/vnd.google-apps.document",
263 }
264 parent := strings.TrimSpace(c.Parent)
265 if parent != "" {
266 f.Parents = []string{parent}
267 }
268
269 if err := dryRunExit(ctx, flags, "docs.create", map[string]any{
270 strFile: f,
271 "sourceFile": c.File,
272 "parent": parent,
273 "pageless": c.Pageless,
274 }); err != nil {
275 return err
276 }
277
278 account, driveSvc, err := requireDriveService(ctx, flags)
279 if err != nil {
280 return err
281 }
282
283 createCall := driveSvc.Files.Create(f).
284 SupportsAllDrives(true).
285 Fields("id, name, mimeType, webViewLink")
286
287 // When --file is set, upload the markdown content and let Drive convert it.
288 var images []markdownImage
289 if c.File != "" {
290 raw, readErr := os.ReadFile(c.File)
291 if readErr != nil {
292 return fmt.Errorf("read markdown file: %w", readErr)
293 }
294 markdown := prepareMarkdown(string(raw))
295 images = markdown.images
296
297 createCall = createCall.Media(
298 strings.NewReader(markdown.cleaned),
299 gapi.ContentType("text/markdown"),
300 )
301 }
302
303 created, err := createCall.Context(ctx).Do()
304 if err != nil {
305 return err
306 }
307 if created == nil {
308 return errors.New("create failed")
309 }
310

Callers

nothing calls this directly

Calls 15

insertImagesMethod · 0.95
FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
dryRunExitFunction · 0.85
requireDriveServiceFunction · 0.85
prepareMarkdownFunction · 0.85
docsServiceFunction · 0.85
setDocumentPagelessFunction · 0.85
stdoutWriterFunction · 0.85
CreateMethod · 0.80

Tested by

no test coverage detected