-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
207 lines (197 loc) · 5.09 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package main
import (
"fmt"
"log"
"os"
"github.com/urfave/cli"
)
// Global configuration
var credentials string
var projectId string
var database string
// Common errors
func cliClientError(err error) *cli.ExitError {
return cli.NewExitError(fmt.Sprintf("Failed to create client. \n%v", err), 80)
}
func main() {
app := cli.NewApp()
app.Version = "0.34.0"
app.Name = "Fuego"
app.Usage = "A firestore client"
app.EnableBashCompletion = true
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "credentials, c",
Destination: &credentials,
Usage: "Load google application credentials from `FILE`",
},
cli.StringFlag{
Name: "projectid, p",
Destination: &projectId,
Usage: "Overwrite project id",
},
cli.StringFlag{
Name: "database, d",
Destination: &database,
Usage: "Overwrite database name ",
},
}
displayFlags := []cli.Flag{
cli.BoolFlag{
Name: "extendedjson, ej",
Usage: "Display documents as extended json",
},
}
deleteFlags := []cli.Flag{
cli.BoolFlag{
Name: "recursive, r",
Usage: "Recursively delete sub-collections",
},
cli.StringFlag{
Name: "field, f",
Usage: "Delete specific field of document",
},
}
app.Commands = []cli.Command{
{
Name: "collections",
Aliases: []string{"c"},
Usage: "List the root level collections",
Action: collectionsCommandAction,
},
{
Name: "add",
Aliases: []string{"a"},
Usage: "Add a new document to a collection",
ArgsUsage: "collection-path json-document",
Action: addCommandAction,
},
{
Name: "set",
Aliases: []string{"s"},
Usage: "Set the contents of a document",
ArgsUsage: "[collection-path document-id json-document | document-path json-document]",
Action: setCommandAction,
Flags: []cli.Flag{cli.BoolFlag{
Name: "merge",
Usage: "if set the set operation will do a update/patch",
}},
},
{
Name: "copy",
Aliases: []string{"s"},
Usage: "copy collection or document",
ArgsUsage: "[collection-path collection-path | document-path document-path]",
Action: copyCommandAction,
Flags: []cli.Flag{
cli.StringFlag{
Name: "dest-credentials, dc",
Usage: "Google application target project credentials from `FILE`",
},
cli.StringFlag{
Name: "src-credentials, sc",
Usage: "Google application source project credentials from `FILE`",
},
cli.StringFlag{
Name: "dest-projectid, dp",
Usage: "Target project ID",
},
cli.StringFlag{
Name: "src-projectid, sp",
Usage: "Source project ID",
},
cli.BoolFlag{
Name: "merge",
Usage: "if set the set operation will do a update/patch",
},
cli.BoolFlag{
Name: "overwrite",
Usage: "overwrite the existing collection or document",
},
},
},
{
Name: "get",
Aliases: []string{"g"},
Usage: "Get a document from a collection",
ArgsUsage: "collection-path [document-id document-path]",
Action: getCommandAction,
Flags: displayFlags,
},
{
Name: "getall",
Aliases: []string{"ga"},
Usage: "Get all document from a collection by providing ids ",
ArgsUsage: "collection-path document-id1 [document-id2 ...]",
Action: getAllCommandAction,
Flags: displayFlags,
},
{
Name: "delete",
Aliases: []string{"d"},
Usage: "Delete a document from a collection",
ArgsUsage: "[collection-path document-id | document-path]",
Action: deleteCommandAction,
Flags: deleteFlags,
},
{
Name: "deleteall",
Aliases: []string{"da"},
Usage: "Delete documents from a collection without transactional support",
ArgsUsage: "collection-path document-id1 [document-id2 ...]",
Action: deleteAllCommandAction,
},
{
Name: "query",
Aliases: []string{"q"},
Usage: "Query a collection",
ArgsUsage: "[collection-path | collection-id] QUERY*",
Action: queryCommandAction,
Flags: append(
displayFlags,
[]cli.Flag{
cli.StringSliceFlag{
Name: "orderby, ob",
Usage: "`FIELD_PATH` to order results by",
},
cli.BoolFlag{
Name: "group, g",
Usage: "perform a group query",
},
cli.StringSliceFlag{
Name: "orderdir, od",
Usage: "`DIRECTION` to order results (options: ASC/DESC)",
},
cli.IntFlag{
Name: "limit, l",
Usage: "Fetch a maximum of `LIMIT` documents",
Value: 100,
},
cli.StringFlag{
Name: "startat, sat",
Usage: "Results start at document `ID`",
},
cli.StringFlag{
Name: "startafter, sar",
Usage: "Results start after document `ID`",
},
cli.StringFlag{
Name: "endat, ea",
Usage: "Results end at document `ID`",
},
cli.StringFlag{
Name: "endbefore, eb",
Usage: "Results end before document `ID`",
},
cli.StringSliceFlag{
Name: "select",
Usage: "Return only `FIELD_PATH` fields in result. Parameter can be given multiple times",
},
}...),
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}