-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
130 lines (90 loc) · 2.54 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
package main
import (
"flag"
"github.com/jroimartin/gocui"
"log"
)
var (
host string
client *mongoClient
colls []string
dbName string
collName string
filter string
)
func main() {
flag.StringVar(&host, "host", "", "Host to connect to ( e.g. mongodb://localhost:27017 )")
flag.StringVar(&dbName, "db", "", "Database to connect to")
flag.Parse()
if host == "" {
log.Println("Please provide a host to connect to")
return
}
c, err := connectToMongoDB()
client = c
if err != nil {
log.Println("Error connecting to MongoDB: ", err)
return
}
collects, err := client.getCollections()
colls = collects
if err != nil {
log.Println("Error getting collections: ", err)
return
}
g, err := gocui.NewGui(gocui.OutputNormal)
if err != nil {
log.Panicln(err)
}
g.Cursor = true
defer g.Close()
g.SetManagerFunc(layout)
if err := g.SetKeybinding("", gocui.KeyCtrlC, gocui.ModNone, quit); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("collections", gocui.KeyArrowDown, gocui.ModNone, nextCursorLine); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("collections", gocui.KeyArrowUp, gocui.ModNone, prevCursorLine); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("collections", gocui.KeyEnter, gocui.ModNone, getLine); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("", gocui.KeyTab, gocui.ModNone, nextView); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("query", gocui.KeyEnter, gocui.ModNone, execute); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("filter", gocui.KeyEnter, gocui.ModNone, readFilter); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("deleteFilter", gocui.KeyEnter, gocui.ModNone, deleteFilter); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("update", gocui.KeyEnter, gocui.ModNone, readUpdate); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("insertOne", gocui.KeyEnter, gocui.ModNone, insertOne); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("results", gocui.KeyArrowUp, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
scrollView(v, -1)
return nil
}); err != nil {
log.Panicln(err)
}
if err := g.SetKeybinding("results", gocui.KeyArrowDown, gocui.ModNone, func(g *gocui.Gui, v *gocui.View) error {
scrollView(v, 1)
return nil
}); err != nil {
log.Panicln(err)
}
if err := g.MainLoop(); err != nil && err != gocui.ErrQuit {
log.Panicln(err)
}
}
func quit(g *gocui.Gui, v *gocui.View) error {
return gocui.ErrQuit
}