forked from zedalaye/bot-spot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
104 lines (94 loc) · 1.84 KB
/
main.go
File metadata and controls
104 lines (94 loc) · 1.84 KB
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 (
"errors"
"fmt"
"log"
"main/commands"
"main/database"
"os"
)
const version = "v3.1.0"
func menu() {
fmt.Println("")
fmt.Println("Cryptomancien - BOT SPOT - " + version + " - beta")
fmt.Println("")
fmt.Println("--new -n Start new cycle")
fmt.Println("--update -u Update running cycles")
fmt.Println("--server -s Start local server")
fmt.Println("--cancel -c Cancel cycle by id - Example: -c 123")
fmt.Println("--auto -a Mode auto")
fmt.Println("--clear -cl Clear range (start end) - Example: -cl 12 36")
fmt.Println("--export -e Export CSV file")
fmt.Println("--restore -r Restore database from JSON file")
fmt.Println("")
}
func initialize() error {
commands.CreateConfigFileIfNotExists()
commands.LoadDotEnv()
// Create an exports folder if not exists
path := "exports"
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
err := os.Mkdir(path, os.ModePerm)
if err != nil {
return err
}
return nil
}
err := database.InitDatabase()
if err != nil {
log.Fatal(err)
}
return nil
}
func main() {
err := initialize()
if err != nil {
panic("Error initializing database: %v")
}
args := os.Args[1:]
if len(args) == 0 {
menu()
return
}
cmd := args[0]
switch cmd {
case "--new", "-n":
err := commands.New()
if err != nil {
log.Fatal(err)
}
break
case "--update", "-u":
err := commands.Update()
if err != nil {
log.Fatal(err)
}
break
case "--server", "-s":
err := commands.Server()
if err != nil {
log.Fatal(err)
}
break
case "--cancel", "-c":
err := commands.Cancel()
if err != nil {
log.Fatal(err)
}
break
case "--clear", "-cl":
err := commands.Clear()
if err != nil {
log.Fatal(err)
}
case "--auto", "-a":
commands.Auto()
break
case "--export", "-e":
commands.Export(true)
break
default:
menu()
return
}
}