(ctx context.Context, kctx *kong.Context, flags *RootFlags)
| 51 | } |
| 52 | |
| 53 | func (c *DocsWriteCmd) Run(ctx context.Context, kctx *kong.Context, flags *RootFlags) error { |
| 54 | id := strings.TrimSpace(c.DocID) |
| 55 | if id == "" { |
| 56 | return usage("empty docId") |
| 57 | } |
| 58 | |
| 59 | text, err := c.resolveWriteText(ctx, kctx) |
| 60 | if err != nil { |
| 61 | return err |
| 62 | } |
| 63 | if c.Append && c.Replace { |
| 64 | return usage("--append cannot be combined with --replace") |
| 65 | } |
| 66 | if c.CheckOrphans && (!c.Markdown || !c.Replace || c.Append) { |
| 67 | return usage("--check-orphans requires --replace --markdown") |
| 68 | } |
| 69 | |
| 70 | tab, tabErr := resolveTabArg(ctx, c.Tab, c.TabID) |
| 71 | if tabErr != nil { |
| 72 | return tabErr |
| 73 | } |
| 74 | c.Tab = tab |
| 75 | |
| 76 | if err := c.validateDocumentStyle(); err != nil { |
| 77 | return err |
| 78 | } |
| 79 | if c.Batch != "" && (c.Markdown || c.Pageless || c.Layout.any()) { |
| 80 | return usage("--batch supports plain text writes without --pageless or layout flags") |
| 81 | } |
| 82 | |
| 83 | if c.Markdown { |
| 84 | if c.Format.any() { |
| 85 | return usage("formatting flags are only supported for plain-text docs write; use markdown syntax or run docs format after writing") |
| 86 | } |
| 87 | return c.writeMarkdown(ctx, flags, id, text) |
| 88 | } |
| 89 | |
| 90 | return c.writePlainText(ctx, flags, id, text) |
| 91 | } |
| 92 | |
| 93 | func (c *DocsWriteCmd) validateDocumentStyle() error { |
| 94 | if !c.Pageless && !c.Layout.any() { |
nothing calls this directly
no test coverage detected