forked from sgarciac/fuego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
188 lines (180 loc) · 4.71 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
package main
import (
"fmt"
"github.com/urfave/cli"
"log"
"os"
)
// Global configuration
var credentials string
var projectId 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.20.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",
},
}
displayFlags := []cli.Flag{
cli.BoolFlag{
Name: "extendedjson, ej",
Usage: "Display documents as extended json",
},
}
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,
},
{
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)
}
}