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

Method Run

internal/cmd/docs_edit.go:673–886  ·  view source on GitHub ↗
(ctx context.Context, kctx *kong.Context, flags *RootFlags)

Source from the content-addressed store, hash-verified

671}
672
673func (c *DocsUpdateCmd) Run(ctx context.Context, kctx *kong.Context, flags *RootFlags) error {
674 u := ui.FromContext(ctx)
675 id := strings.TrimSpace(c.DocID)
676 if id == "" {
677 return usage("empty docId")
678 }
679
680 text, provided, err := resolveTextInput(ctx, c.Text, c.File, kctx)
681 if err != nil {
682 return err
683 }
684 if !provided {
685 return usage("required: --text or --file")
686 }
687 if text == "" {
688 return usage("empty text")
689 }
690 placement, err := docsedit.PlanUpdatePlacement(docsedit.UpdatePlacementOptions{
691 Index: c.Index,
692 IndexProvided: flagProvided(kctx, "index"),
693 AllowZero: strings.TrimSpace(c.Segment) != "",
694 ReplaceRange: c.ReplaceRange,
695 Anchor: docsedit.AnchorOptions{
696 Text: c.At,
697 Provided: flagProvided(kctx, "at"),
698 Occurrence: c.Occurrence,
699 MatchCase: c.MatchCase,
700 },
701 })
702 if err != nil {
703 return usage(err.Error())
704 }
705 at := placement.Anchor.Text
706 replacing := placement.Kind == docsedit.PlacementRange
707 replaceRange := placement.Range
708 replaceStart, replaceEnd := replaceRange.Start, replaceRange.End
709
710 tab, tabErr := resolveTabArg(ctx, c.Tab, c.TabID)
711 if tabErr != nil {
712 return tabErr
713 }
714 c.Tab = tab
715 if strings.TrimSpace(c.Segment) != "" && c.Markdown {
716 return usage("--segment supports plain-text updates only; markdown can contain structures that are invalid in segments")
717 }
718 if c.Batch != "" && (c.Markdown || c.Pageless) {
719 return usage("--batch supports plain text updates without --pageless")
720 }
721 if dryRunErr := dryRunExit(ctx, flags, "docs.update", c.dryRunPayload(id, len(text), replacing, replaceStart, replaceEnd, at)); dryRunErr != nil {
722 return dryRunErr
723 }
724 if batchErr := validateDocsBatchTarget(ctx, flags, c.Batch, id); batchErr != nil {
725 return batchErr
726 }
727
728 svc, err := requireDocsService(ctx, flags)
729 if err != nil {
730 return err

Callers 1

Calls 15

dryRunPayloadMethod · 0.95
FromContextFunction · 0.92
PlanUpdatePlacementFunction · 0.92
ExplicitHeadingAnchorsFunction · 0.92
BuildUpdateRequestsFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
resolveTextInputFunction · 0.85
flagProvidedFunction · 0.85
resolveTabArgFunction · 0.85
dryRunExitFunction · 0.85

Tested by 1