-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.11 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
)
var inputFile string
var outputFile string
var appendText string
func main() {
rootCmd := &cobra.Command{
Use: "docx-append",
Short: "A simple CLI to append text to a DOCX file",
Run: func(cmd *cobra.Command, args []string) {
if inputFile == "" || outputFile == "" || appendText == "" {
fmt.Println("Error: Missing required flags.")
cmd.Help()
os.Exit(1)
}
d, err := docx.ReadDocxFromFS(inputFile)
if err != nil {
log.Fatal("Error reading input file:", err)
}
d.AppendText(appendText)
err = d.WriteToFile(outputFile)
if err != nil {
log.Fatal("Error writing output file:", err)
}
fmt.Println("Text successfully appended and saved to output file.")
},
}
rootCmd.Flags().StringVarP(&inputFile, "input", "i", "", "Input DOCX file path")
rootCmd.Flags().StringVarP(&outputFile, "output", "o", "", "Output DOCX file path")
rootCmd.Flags().StringVarP(&appendText, "text", "t", "", "Text to append to the DOCX file")
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}