-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
114 lines (103 loc) · 2.53 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
105
106
107
108
109
110
111
112
113
114
package main
import (
_ "embed"
"fmt"
"os"
"strings"
"github.com/tesselslate/resetti/internal/cfg"
"github.com/tesselslate/resetti/internal/ctl"
"github.com/tesselslate/resetti/internal/log"
"github.com/tesselslate/resetti/internal/res"
)
//go:embed .notice
var notice string
//go:embed .version
var version string
func main() {
// Setup logger output.
logPath, ok := os.LookupEnv("RESETTI_LOG_PATH")
if !ok {
logPath = "/tmp/resetti.log"
}
logger := log.DefaultLogger(log.INFO, logPath, false)
logger.Info("Started Logger")
defer func() {
logger.Close()
}()
if err := res.WriteResources(); err != nil {
logger.Error("Failed to write resources: %s", err)
os.Exit(1)
}
if len(os.Args) < 2 {
printHelp()
os.Exit(1)
}
switch os.Args[1] {
case "--help", "-h", "help":
printHelp()
case "--version", "version":
fmt.Print(
"\n resetti ",
strings.Trim(version, "\n"),
" - Minecraft resetting macro\n",
notice,
)
case "new":
if len(os.Args) < 3 {
printHelp()
os.Exit(1)
}
err := cfg.MakeProfile(os.Args[2])
if err != nil {
logger.Error("Failed to make profile: %s", err)
} else {
logger.Info("Created profile!")
}
case "-d", "--debug":
logger.Info("Running in debug mode.")
logger.SetLevel(log.DEBUG)
if len(os.Args) < 3 {
logger.Error("Expected profile name after -d, --debug.")
printHelp()
os.Exit(1)
}
profileName := os.Args[2]
Run(profileName)
default:
if len(os.Args) >= 3 {
if os.Args[2] == "-d" || os.Args[2] == "--debug" {
logger.Info("Running in debug mode.")
logger.SetLevel(log.DEBUG)
}
}
profileName := os.Args[1]
Run(profileName)
}
}
func Run(profileName string) {
// Get configuration and run.
profile, err := cfg.GetProfile(profileName)
if err != nil {
log.Error("Failed to get profile: %s", err)
return
}
if err = ctl.Run(&profile); err != nil {
log.Error("Failed to run: %s", err)
return
}
}
func printHelp() {
fmt.Println(`
resetti - Minecraft resetting macro
USAGE:
resetti [PROFILE] Run resetti with the given profile.
--force-log Force the latest.log reader to be used.
--force-wpstate Force the wpstateout.txt reader to be used.
-d, --debug Run resetti in debug mode.
SUBCOMMANDS:
resetti new [PROFILE] Create a new profile named PROFILE with
the default configuration.
resetti help Print this message.
resetti version Get the version of resetti installed.
`)
}