-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
48 lines (39 loc) · 949 Bytes
/
client.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
package main
import (
"bufio"
"flag"
"fmt"
log "github.com/Sirupsen/logrus"
"os"
"strings"
)
func main() {
pathToConfig := flag.String("config", "", "Config not found")
flag.Parse()
if *pathToConfig == "" {
log.Fatal("Config not specified")
}
config := ReadConfig(*pathToConfig)
if config != nil {
if _, err := os.Stat(config.DefaultPathToSave); os.IsNotExist(err) {
log.Fatal("Specified directory to downloading files is not exists, change default-path-to-save in " + *pathToConfig)
}
reader := bufio.NewReader(os.Stdin)
for {
fmt.Print("-> ")
input, err := reader.ReadString('\n')
if err != nil {
log.WithField("error", err.Error()).Error("Read command error")
} else {
input = strings.Trim(input, "\n")
command := makeCommand(input, config)
fmt.Println(command.Do())
if command.isExitCommand() {
os.Exit(0)
}
}
}
} else {
log.Fatal("Handling config error!")
}
}