-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
63 lines (52 loc) · 962 Bytes
/
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
package main
import (
"context"
"fmt"
"io"
"strings"
"time"
"github.com/peterh/liner"
"cloud.google.com/go/firestore"
)
var (
client *firestore.Client
ctx context.Context
err error
collection string
)
func prompt() string {
return fmt.Sprintf("<%s> ", time.Now().Format("Jan 2 15:04:05.000"))
}
func main() {
// Initialize commands
commandsInit()
// Create firebase client
//connect([]string{})
// Start loop with history and completion
_ = interactiveLoop()
}
func interactiveLoop() error {
s := liner.NewLiner()
s.SetTabCompletionStyle(liner.TabPrints)
s.SetCompleter(func(line string) (ret []string) {
for _, c := range commandKeys {
if strings.HasPrefix(c, line) {
ret = append(ret, c)
}
}
return
})
defer func() { _ = s.Close() }()
for {
p, err := s.Prompt(prompt())
if err == io.EOF {
return nil
}
if err != nil {
panic(err)
}
if executeCommand(p) {
s.AppendHistory(p)
}
}
}