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

Method Run

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

Source from the content-addressed store, hash-verified

928}
929
930func (c *DocsInsertCmd) Run(ctx context.Context, kctx *kong.Context, flags *RootFlags) error {
931 u := ui.FromContext(ctx)
932 docID := strings.TrimSpace(c.DocID)
933 if docID == "" {
934 return usage("empty docId")
935 }
936 content, err := resolveContentInput(ctx, c.Content, c.File)
937 if err != nil {
938 return err
939 }
940 if content == "" {
941 return usage("no content provided (use argument, --file, or stdin)")
942 }
943 placement, err := docsedit.PlanInsertPlacement(docsedit.InsertPlacementOptions{
944 Index: c.Index,
945 AllowZero: strings.TrimSpace(c.Segment) != "",
946 Anchor: docsedit.AnchorOptions{
947 Text: c.At,
948 Provided: flagProvided(kctx, "at"),
949 Occurrence: c.Occurrence,
950 MatchCase: c.MatchCase,
951 },
952 })
953 if err != nil {
954 return usage(err.Error())
955 }
956 at := placement.Anchor.Text
957
958 tab, tabErr := resolveTabArg(ctx, c.Tab, c.TabID)
959 if tabErr != nil {
960 return tabErr
961 }
962 c.Tab = tab
963 if strings.TrimSpace(c.Segment) != "" && c.Markdown {
964 return usage("--segment supports plain-text inserts only; markdown can contain structures that are invalid in segments")
965 }
966 if c.Markdown && c.Batch != "" {
967 return usage("--markdown cannot be combined with --batch")
968 }
969 dryRunPayload := map[string]any{
970 "documentId": docID,
971 "inserted": len(content),
972 "markdown": c.Markdown,
973 "tab": c.Tab,
974 "segment": c.Segment,
975 "batch": c.Batch,
976 }
977 switch placement.Kind {
978 case docsedit.PlacementAnchor:
979 dryRunPayload["atIndex"] = docsAtIndexAnchorStart
980 addDocsAtAnchorDryRunPayload(dryRunPayload, docsAtAnchorFlags{At: at, Occurrence: c.Occurrence, MatchCase: c.MatchCase})
981 case docsedit.PlacementIndex:
982 dryRunPayload["atIndex"] = placement.Index
983 default:
984 dryRunPayload["atIndex"] = docsAtIndexEnd
985 }
986 if dryRunErr := dryRunExit(ctx, flags, "docs.insert", dryRunPayload); dryRunErr != nil {
987 return dryRunErr

Callers

nothing calls this directly

Calls 15

runMarkdownMethod · 0.95
FromContextFunction · 0.92
PlanInsertPlacementFunction · 0.92
BuildInsertRequestFunction · 0.92
IsJSONFunction · 0.92
WriteJSONFunction · 0.92
usageFunction · 0.85
resolveContentInputFunction · 0.85
flagProvidedFunction · 0.85
resolveTabArgFunction · 0.85
dryRunExitFunction · 0.85

Tested by

no test coverage detected