Merge pull request 'feat(docs): oo docs comment --base (#90)' (#91) from feat/docs-comment-base#90 into main
Release / GoReleaser (push) Skipped
Tests / Secret scan (gitleaks) (push) Successful in 4s
Tests / Test (Go 1.25) (push) Successful in 1m32s
Tests / Test (Go stable) (push) Successful in 1m32s

This commit was merged in pull request #91.
This commit is contained in:
2026-10-07 18:33:53 +01:00
+12 -2
View File
@@ -12,7 +12,7 @@ import (
) )
func docsCommentCmd() *cobra.Command { func docsCommentCmd() *cobra.Command {
var spec, author, out string var spec, author, out, basePath string
var replace bool var replace bool
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "comment FILE_ID", Use: "comment FILE_ID",
@@ -65,14 +65,23 @@ text split across runs. At most one comment lands on a paragraph.
return fmt.Errorf("%s is not a .docx (comments need Word format)", title) return fmt.Errorf("%s is not a .docx (comments need Word format)", title)
} }
var base []byte
if basePath != "" {
base, err = os.ReadFile(basePath)
if err != nil {
return err
}
} else {
var buf bytes.Buffer var buf bytes.Buffer
if _, err := c.DownloadFile(ctx, args[0], &buf); err != nil { if _, err := c.DownloadFile(ctx, args[0], &buf); err != nil {
return err return err
} }
base = buf.Bytes()
}
if author == "" { if author == "" {
author = selfDisplayName(cmd) author = selfDisplayName(cmd)
} }
annotated, applied, err := onlyoffice.InjectDocxComments(buf.Bytes(), author, comments) annotated, applied, err := onlyoffice.InjectDocxComments(base, author, comments)
if err != nil { if err != nil {
return err return err
} }
@@ -124,6 +133,7 @@ text split across runs. At most one comment lands on a paragraph.
cmd.Flags().StringVar(&spec, "spec", "", "JSON file: [{\"anchor\":...,\"text\":...}] (required)") cmd.Flags().StringVar(&spec, "spec", "", "JSON file: [{\"anchor\":...,\"text\":...}] (required)")
cmd.Flags().StringVar(&author, "author", "", "comment author (default: the authenticated portal user)") cmd.Flags().StringVar(&author, "author", "", "comment author (default: the authenticated portal user)")
cmd.Flags().StringVar(&out, "out", "", "local output path (default: <title> - comments.docx)") cmd.Flags().StringVar(&out, "out", "", "local output path (default: <title> - comments.docx)")
cmd.Flags().StringVar(&basePath, "base", "", "local clean .docx to annotate instead of downloading FILE_ID (re-apply without stacking comments)")
cmd.Flags().BoolVar(&replace, "replace", false, "upload the annotated copy back over the same file id") cmd.Flags().BoolVar(&replace, "replace", false, "upload the annotated copy back over the same file id")
return cmd return cmd
} }