-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCvtGdocToHtml.go
128 lines (108 loc) · 2.84 KB
/
CvtGdocToHtml.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// v1 change doc to Par NTest
// v2 start a text debug
// v3 loop through some elements
// 9/12/21
// split into two packages
// CvtGdocToTxt
// CvtGdocToHtml
//
//
package main
import (
"fmt"
"os"
"strings"
gdocApi "google/gdoc/gdocApi"
gdocHtml "google/gdoc/gdocHtml"
)
func main() {
var gd gdocApi.GdocApiStruct
numArgs := len(os.Args)
// fmt.Printf("args: %d\n", numArgs)
cmd := os.Args[0]
opt:=""
switch numArgs {
case 1:
fmt.Println("error - no comand line arguments!")
fmt.Printf("%s usage is:\n %s docId opt [sumary, main, all]\n", cmd[2:], cmd)
os.Exit(1)
case 2:
fmt.Println("no option argument provided!")
fmt.Println("assuming 'opt = all'!")
opt = "all"
case 3:
case 4:
opt = os.Args[3]
default:
fmt.Println("error - too many arguments!")
fmt.Printf("%s usage is:\n %s docId opt [sumary, main, all]\n", cmd[2:], cmd)
os.Exit(1)
}
docId := os.Args[1]
err := gd.InitGdocApi()
if err != nil {
fmt.Printf("error - InitGdocApi: %v!", err)
os.Exit(1)
}
srv := gd.Svc
outfilPath:= ""
switch {
case os.Args[2] == "output":
outfilPath = os.Args[2]
case strings.Index(os.Args[2], "output/")< 0:
outfilPath = "output/" + os.Args[2]
case strings.Index(os.Args[2], "output/") == 0:
outfilPath = os.Args[2]
case os.Args[2] == "":
outfilPath = "output"
default:
fmt.Printf("no valid input folder: %s", os.Args[2])
os.Exit(1)
}
fmt.Printf("*************** CctGdocToHtml ************\n")
fmt.Printf("output folder: %s option: %s\n", outfilPath, opt)
doc, err := srv.Documents.Get(docId).Do()
if err != nil {
fmt.Println("Unable to retrieve data from document: ", err)
os.Exit(1)
}
fmt.Printf("Doc Title: %s Option: %s\n", doc.Title, opt)
switch opt {
case "heading":
err = gdocHtml.CreGdocHtmlSection("", outfilPath, doc, nil)
if err != nil {
fmt.Println("error main: CreGdocHtmlSummary -- cannot convert gdoc doc: ", err)
os.Exit(1)
}
fmt.Println("*** success summary ***!")
os.Exit(0)
case "main":
err = gdocHtml.CreGdocHtmlMain(outfilPath, doc, nil)
if err != nil {
fmt.Println("error main CreGdocHtmlMain -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success main ***!")
os.Exit(0)
case "doc":
err = gdocHtml.CreGdocHtmlDoc(outfilPath, doc, nil)
if err != nil {
fmt.Println("error CreGdocHtmlDoc -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success all ***!")
os.Exit(0)
case "all":
err = gdocHtml.CreGdocHtmlAll(outfilPath, doc, nil)
if err != nil {
fmt.Println("error CreGdocHtmlAll -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success all ***!")
os.Exit(0)
default:
fmt.Printf("did not provide a valid opt: %s\n", opt)
fmt.Println("failure!")
os.Exit(1)
}
}