-
Notifications
You must be signed in to change notification settings - Fork 0
/
CvtGdocToDom.go
141 lines (118 loc) · 3.15 KB
/
CvtGdocToDom.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
129
130
131
132
133
134
135
136
137
138
139
140
141
//
// CvtGdocToDom
// date: 22. April 2022
// author: prr
// copyright 2022 prr azul software
//
// gdocHtml "google/gdoc/gdocHtml"
package main
import (
"fmt"
"os"
"strings"
gdocApi "google/gdoc/gdocApi"
gdocDom "google/gdoc/gdocDom"
)
func main() {
var gd gdocApi.GdocApiStruct
// initialise default values
baseFolder := "output"
baseFolderSlash := baseFolder + "/"
opt:=""
numArgs := len(os.Args)
// fmt.Printf("args: %d\n", numArgs)
cmd := os.Args[0]
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 numArgs == 2:
outfilPath = baseFolder
case os.Args[2] == baseFolder:
outfilPath = os.Args[2]
case strings.Index(os.Args[2], baseFolderSlash)< 0:
outfilPath = baseFolderSlash + os.Args[2]
case strings.Index(os.Args[2], baseFolderSlash) == 0:
outfilPath = os.Args[2]
case os.Args[2] == "":
outfilPath = baseFolder
default:
fmt.Printf("no valid input folder: %s", os.Args[2])
os.Exit(1)
}
fmt.Printf("*************** CvtGdocToDom ************\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":
fmt.Printf("*** not implemented yet ***\n")
os.Exit(1)
// err = gdocHtml.CreGdocHtmlSection("", outfilPath, doc, nil)
if err != nil {
fmt.Println("error main: CreGdocDomSummary -- cannot convert gdoc doc: ", err)
os.Exit(1)
}
fmt.Println("*** success summary ***!")
os.Exit(0)
case "main":
fmt.Printf("*** not implemented yet ***\n")
os.Exit(1)
// err = gdocHtml.CreGdocHtmlMain(outfilPath, doc, nil)
if err != nil {
fmt.Println("error main CreGdocDomMain -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success main ***!")
os.Exit(0)
case "doc":
fmt.Printf("*** not implemented yet ***\n")
os.Exit(1)
// err = gdocHtml.CreGdocHtmlDoc(outfilPath, doc, nil)
if err != nil {
fmt.Println("error CreGdocDomDoc -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success doc ***!")
os.Exit(0)
case "all":
err = gdocDom.CreGdocDomAll(outfilPath, doc, nil)
if err != nil {
fmt.Println("error CreGdocDomAll -- cannot convert gdoc file: ", err)
os.Exit(1)
}
fmt.Println("*** success all ***!")
os.Exit(0)
default:
fmt.Printf("%s is not a valid comand line opt!\n", opt)
fmt.Println("exiting!")
os.Exit(1)
}
fmt.Println("Success!")
}