-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathhandler.go
187 lines (169 loc) · 4.41 KB
/
handler.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Package main (handler.go) :
// Handler for ggsrun
package main
import (
"encoding/json"
"fmt"
"os"
"ggsrun/utl"
"github.com/urfave/cli"
)
// exeAPIWithout : exe1
// Update project and Execution API withour server script.
func exeAPIWithout(c *cli.Context) error {
defAuthContainer(c).
ggsrunIni(c).
goauth().
defExecutionContainer().
exe1Function(c).
executionAPIwithoutServer(c).
esenderForExe1(c).
dispResult(c)
return nil
}
// exeAPIWith : exe2
// No update project. Only execute GAS using Execution API with server script.
func exeAPIWith(c *cli.Context) error {
defAuthContainer(c).
ggsrunIni(c).
goauth().
defExecutionContainer().
exe2Function(c).
dispResult(c)
return nil
}
// webAppsWith : exe3
// No update project. Only execute GAS using Web Apps with server script.
func webAppsWith(c *cli.Context) error {
defExecutionContainerWebApps().
webAppswithServerForExe3(utl.ConvGasToRun(c), c).
dispResult(c)
return nil
}
// downloadFiles : Download files from Google Drive.
func downloadFiles(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defDownloadContainer(c).
GetFileinf().
Downloader(c)
dispTransferResult(c, res)
return nil
}
// uploadFiles : Uploads files
func uploadFiles(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defUploadContainer(c).
Uploader(c)
dispTransferResult(c, res)
return nil
}
// updateProject : Updates projects and scripts
func updateProject(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defExecutionContainer().
projectUpdateControl(c)
dispTransferResult(c, res)
return nil
}
// revisionFiles : Retrieves revision IDs and downloads revision files.
func revisionFiles(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defDownloadContainer(c).
GetRevisionList(c)
dispTransferResult(c, res)
return nil
}
// showFileList : Shows file list on Google Drive
func showFileList(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defDownloadContainer(c).
GetFileList(c)
dispTransferResult(c, res)
return nil
}
// searchFilesByQueryAndRegex : Search files on Google Drive using search query and regex.
func searchFilesByQueryAndRegex(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defDownloadContainer(c).
SearchFiles()
dispTransferResult(c, res)
return nil
}
// managePermissions : Manage permissions.
func managePermissions(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defPermissionsContainer(c).
ManagePermissions()
dispTransferResult(c, res)
return nil
}
// getDriveInformation : Get drive information.
func getDriveInformation(c *cli.Context) error {
res := defAuthContainer(c).
ggsrunIni(c).
goauth().
defDownloadContainer(c).
GetDriveInformation()
dispTransferResult(c, res)
return nil
}
// reAuth : Retrieve tokens again.
func reAuth(c *cli.Context) error {
defAuthContainer(c).
ggsrunIni(c).
reAuth()
fmt.Print("Done.")
return nil
}
// dispResult : Display result
func (e *ExecutionContainer) dispResult(c *cli.Context) {
var dispRes []byte
if len(e.Msg) > 0 {
e.FeedBackData.Response.Result.Message = e.Msg
}
if c.Bool("jsonparser") {
dispRes, _ = json.MarshalIndent(e.FeedBackData.Response.Result, "", " ")
} else {
dispRes, _ = json.Marshal(e.FeedBackData.Response.Result)
}
if c.Bool("onlyresult") {
if c.Bool("jsonparser") {
onlyres, _ := json.MarshalIndent(e.FeedBackData.Response.Result.Result, "", " ")
fmt.Printf("%s\n", string(onlyres))
} else {
onlyres, _ := json.Marshal(e.FeedBackData.Response.Result.Result)
fmt.Printf("%s\n", string(onlyres))
}
} else {
fmt.Printf("%v\n", string(dispRes))
}
}
// dispTransferResult : Display result
func dispTransferResult(c *cli.Context, f *utl.FileInf) {
var dispRes []byte
if c.Bool("jsonparser") {
dispRes, _ = json.MarshalIndent(f, "", " ")
} else {
dispRes, _ = json.Marshal(f)
}
fmt.Printf("%s\n", string(dispRes))
}
// commandNotFound :
func commandNotFound(c *cli.Context, command string) {
fmt.Fprintf(os.Stderr, "'%s' is not a %s command. Check '%s --help' or '%s -h'.", command, c.App.Name, c.App.Name, c.App.Name)
os.Exit(2)
}