-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.24 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"io"
"os"
"github.com/FiftyLinesOfCode/wordide/wordide"
)
const (
PROG_NAME string = "wide"
PROG_VERSION_MAJOR int = 1
PROG_VERSION_MINOR int = 0
)
func printUsage() {
println("USAGE: wide <command> <filename>.odt")
println("Available commands:")
println("\tcompile - Outputs plain text in stdout")
println("\thelp - displays this page")
}
func main() {
args := os.Args
if len(args) <= 2 {
printUsage()
return
}
switch args[1] {
case "help":
printUsage()
return
case "compile":
ctx, err := wordide.OpenContext(args[2])
if err != nil {
println("Can't open a context. Are you sure the file specified exists?")
return
}
defer ctx.Close()
file, err := ctx.GetFile("content.xml")
if err != nil {
println("The specified file doesn't contain a content.xml. Are you sure it's a valid .odt file?")
return
}
reader, _ := file.Open()
fileContent, err := io.ReadAll(reader)
if err != nil {
println("Failed to read from content.xml")
return
}
generated, err := wordide.Parse(fileContent)
if err != nil {
println("Couldn't parse content.xml. Are you sure it's a valid .odt file?")
return
}
fmt.Println(generated)
default:
printUsage()
return
}
}