-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
104 lines (85 loc) · 1.73 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
package main
import (
"bufio"
"fmt"
"os"
"strings"
cO "github.com/MrBolas/URLWatcher/console"
"github.com/MrBolas/URLWatcher/models"
)
func main() {
// read urls from file
// Create Manager
var wM models.WatcherManager
// Build a cmd line prompt waiting for inputs
// Available commands:
// load: load file from path
// add: url to add
// list: lists watchers
// kill: kills watcher
// start: starts watchers
reader := bufio.NewReader(os.Stdin)
fmt.Println("----------URL Watcher Shell-----------")
for {
fmt.Print("-> ")
text, _ := reader.ReadString('\n')
// convert CRLF to LF
text = strings.Replace(text, "\n", "", -1)
// Load File
if strings.HasPrefix(text, "load") {
args, err := cO.SanitizeInputs(text)
if err != nil {
fmt.Println(err)
continue
}
urls, err := cO.ReadUrlsFromFile(args[0])
if err != nil {
fmt.Println(err)
continue
}
wM.AddWatchers(urls)
continue
}
// Add Url
if strings.HasPrefix(text, "add") {
args, err := cO.SanitizeInputs(text)
if err != nil {
fmt.Println(err)
continue
}
urls := cO.ConvertToUrl(args)
wM.AddWatchers(urls)
continue
}
// list watchers
if strings.HasPrefix(text, "ls") {
wM.PrintStatus()
continue
}
// Start watchers
if strings.HasPrefix(text, "start") {
args, err := cO.SanitizeInputs(text)
if err != nil {
fmt.Println(err)
continue
}
if args[0] == "all" {
wM.Start()
} else {
wM.StartById(args)
}
continue
}
// stop watcher
if strings.HasPrefix(text, "stop") {
args, err := cO.SanitizeInputs(text)
if err != nil {
fmt.Println(err)
continue
}
wM.StopWatcher(args[0])
continue
}
fmt.Println("Unknown command")
}
}