(ctx context.Context, kctx *kong.Context, flags *RootFlags)
| 928 | } |
| 929 | |
| 930 | func (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 |
nothing calls this directly
no test coverage detected