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

Method Run

internal/cmd/slides_insert_image.go:38–163  ·  view source on GitHub ↗
(ctx context.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

36}
37
38func (c *SlidesInsertImageCmd) Run(ctx context.Context, flags *RootFlags) error {
39 u := ui.FromContext(ctx)
40
41 presentationID := strings.TrimSpace(c.PresentationID)
42 if presentationID == "" {
43 return usage("empty presentationId")
44 }
45 slideID := strings.TrimSpace(c.SlideID)
46 if slideID == "" {
47 return usage("empty slideId")
48 }
49 if c.Width <= 0 {
50 return usage("--width must be greater than 0")
51 }
52 if c.Height < 0 {
53 return usage("--height cannot be negative")
54 }
55
56 source, err := resolveSlidesImageSource(c.Image, c.URL)
57 if err != nil {
58 return err
59 }
60
61 // Resolve height from the image's aspect ratio when not supplied.
62 height := c.Height
63 if height == 0 {
64 if source.imageURL != "" {
65 return usage("--height is required with --url")
66 }
67 ar, aspectErr := imageAspectRatio(source.localPath)
68 if aspectErr != nil {
69 return fmt.Errorf("determine image aspect ratio (pass --height to skip): %w", aspectErr)
70 }
71 height = c.Width * ar
72 }
73
74 dryRunPayload := map[string]any{
75 "presentation_id": presentationID,
76 "slide_id": slideID,
77 "x": c.X,
78 "y": c.Y,
79 "width": c.Width,
80 "height": height,
81 "unit": c.Unit,
82 }
83 if source.imageURL != "" {
84 dryRunPayload["url"] = source.imageURL
85 } else {
86 dryRunPayload["image"] = source.localPath
87 dryRunPayload["mime_type"] = source.mimeType
88 }
89 if dryRunErr := dryRunExit(ctx, flags, "slides.insert-image", dryRunPayload); dryRunErr != nil {
90 return dryRunErr
91 }
92
93 account, err := requireAccount(flags)
94 if err != nil {
95 return err

Calls 15

FromContextFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
resolveSlidesImageSourceFunction · 0.85
imageAspectRatioFunction · 0.85
dryRunExitFunction · 0.85
requireAccountFunction · 0.85
slidesServiceFunction · 0.85
findSlidesPageByIDFunction · 0.85
prepareSlidesImageURLFunction · 0.85