-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.go
56 lines (52 loc) · 909 Bytes
/
cli.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func SetupCLIHandler() {
r := bufio.NewReader(os.Stdin)
go func() {
for {
line, err := r.ReadString('\n')
if err != nil {
fmt.Println("Error reading from stdin:", err)
return
}
done := ProcessCommand(line)
if !done {
fmt.Println("Invalid Command")
} else {
fmt.Println("Done")
}
}
}()
}
func ProcessCommand(command string) bool {
arguments := strings.Split(command, " ")
if len(arguments) < 1 {
return false
}
for agrId := 0; agrId < len(arguments); agrId++ {
arguments[0] = strings.TrimSpace(arguments[0])
}
switch arguments[0] {
case "user":
switch arguments[1] {
case "add":
if len(arguments) != 4 {
return false
}
AddUser(arguments[2], arguments[3])
return true
}
case "exit":
os.Exit(0)
return true
case "migrate":
Migrate()
return true
}
return false
}