-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (64 loc) · 1.34 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
package main
import (
"fmt"
"github.com/adamcolton/luce/lerr"
"github.com/adamcolton/luce/util/cli"
"github.com/adamcolton/luce/util/handler"
"github.com/adamcolton/luce/util/unixsocket"
)
type User struct {
Name, Password string
}
func main() {
err := unixsocket.
New("/tmp/socket-demo.sock", nil).
Runner(setCommands).
Run()
lerr.Panic(err)
}
func setCommands(r *cli.Runner) {
r.Prompt = "> "
r.StartMessage = "Welcome to the commands demo\nenter 'help' for more\n"
r.Commands = handler.Must([]handler.Command{
{
Name: "",
Action: func() {
r.WriteString("Unrecognized Command\nEnter 'help' to see commands\n")
},
}, {
Name: "help",
Usage: "show this menu",
Action: func() {
r.ShowCommands()
},
}, {
Name: "close",
Usage: "the server (and client)",
Action: func() {
r.WriteString("Closing Server. Goodbye\n")
r.Close = true
r.Exit = true
},
}, {
Name: "exit",
Usage: "exit the client",
Action: func() {
r.WriteString("Closing Client. Goodbye\n")
r.Exit = true
},
}, {
Name: "sayHi",
Usage: "says hi",
Action: func() {
r.WriteString("Hi!")
},
}, {
Name: "user",
Usage: "create user",
Action: func(u *User) {
fmt.Printf("Create User\n\tName: %s\n\tPassword: %s", u.Name, u.Password)
r.WriteString(" Created User")
},
},
})
}