diff --git a/cmd/oo/docs_comment.go b/cmd/oo/docs_comment.go index ac00cd1..a18956f 100644 --- a/cmd/oo/docs_comment.go +++ b/cmd/oo/docs_comment.go @@ -12,7 +12,7 @@ import ( ) func docsCommentCmd() *cobra.Command { - var spec, author, out string + var spec, author, out, basePath string var replace bool cmd := &cobra.Command{ 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) } - var buf bytes.Buffer - if _, err := c.DownloadFile(ctx, args[0], &buf); err != nil { - return err + var base []byte + if basePath != "" { + base, err = os.ReadFile(basePath) + if err != nil { + return err + } + } else { + var buf bytes.Buffer + if _, err := c.DownloadFile(ctx, args[0], &buf); err != nil { + return err + } + base = buf.Bytes() } if author == "" { author = selfDisplayName(cmd) } - annotated, applied, err := onlyoffice.InjectDocxComments(buf.Bytes(), author, comments) + annotated, applied, err := onlyoffice.InjectDocxComments(base, author, comments) if err != nil { 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(&author, "author", "", "comment author (default: the authenticated portal user)") cmd.Flags().StringVar(&out, "out", "", "local output path (default: - 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") return cmd }