-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconsole_reader.go
64 lines (62 loc) · 1.45 KB
/
console_reader.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
package main
import (
"bufio"
"log"
"os"
"path/filepath"
"strings"
)
func handleConsole() {
defer close(g_FileWatcher.doneEvent)
defer close(g_FileSyncer.doneEvent)
defer g_WaitGroup.Done()
inputReader := bufio.NewReader(os.Stdin)
for {
input, err := inputReader.ReadString('\n')
if err != nil {
log.Printf("read input:%s error:%v\n", input, err)
break
}
input = strings.Replace(input, "\r\n", "", -1)
input = strings.Replace(input, "\n", "", -1)
cmds := strings.Split(input, " ")
switch {
case cmds[0] == "sync":
{
if len(cmds) < 2 {
log.Print("sync lost dir/file path args\n")
break
}
syncPath := filepath.Join(g_SyncCfg.LocalDir, cmds[1])
log.Printf("usr cmd sync:%s\n", syncPath)
g_FileSyncer.syncEvent <- syncPath
}
case cmds[0] == "remove":
{
if len(cmds) < 2 {
log.Print("remove lost dir/file path args\n")
break
}
removePath := filepath.Join(g_SyncCfg.LocalDir, cmds[1])
log.Printf("usr cmd remove:%s\n", removePath)
g_FileSyncer.removeEvent <- removePath
}
case cmds[0] == "help":
{
log.Print("sync local dir/file to remote: sync dirpath/filepath\n")
log.Print("remove remote dir/file: remote dirpath/filepath\n")
log.Print("quit app: exit or quit\n")
}
case cmds[0] == "exit" || cmds[0] == "quit":
{
return
}
default:
{
if len(input) > 0 {
log.Printf("unkonw cmd:%s\nenter 'help' for usage\n", input)
}
}
}
}
}