-
Notifications
You must be signed in to change notification settings - Fork 28
/
main.go
146 lines (138 loc) · 3.48 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
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.12.1"
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",
},
}
writingFlags := []cli.Flag{
cli.BoolFlag{
Name: "timestamp, ts",
Usage: "treat strings values that match rfc3339 as timestamps",
},
}
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,
Flags: writingFlags,
},
{
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: append(
writingFlags,
cli.BoolFlag{
Name: "merge",
Usage: "if set the set operation will do a update/patch",
},
),
},
{
Name: "get",
Aliases: []string{"g"},
Usage: "Get a document from a collection",
ArgsUsage: "[collection-path document-id | document-path]",
Action: getCommandAction,
},
{
Name: "delete",
Aliases: []string{"d"},
Usage: "Delete a document from a collection",
ArgsUsage: "[collection-path document-id | document-path]",
Action: deleteCommandAction,
},
{
Name: "query",
Aliases: []string{"q"},
Usage: "Query a collection",
ArgsUsage: "[collection-path | collection-id] QUERY*",
Action: queryCommandAction,
Flags: []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",
},
cli.IntFlag{
Name: "batch, b",
Usage: "Will fetch documents in several requests with at most `BATCH` documents per request to prevent timeouts (currently 60s).",
Value: 100000,
},
},
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}