Merge pull request 'feat(docs): oo docs comment --base (#90)' (#91) from feat/docs-comment-base#90 into main
This commit was merged in pull request #91.
This commit is contained in:
+15
-5
@@ -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: <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")
|
||||
return cmd
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user