-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (48 loc) · 918 Bytes
/
main.go
File metadata and controls
57 lines (48 loc) · 918 Bytes
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
package main
import (
"fmt"
"github.com/Xtendera/visor/client"
"github.com/Xtendera/visor/config"
"github.com/Xtendera/visor/util"
"log/slog"
"os"
)
func incorrectArg() {
fmt.Printf("Invalid subcommand!\n")
os.Exit(1)
}
func runCfg() {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
if len(os.Args) < 3 {
slog.Error("No configuration path provided!\n")
os.Exit(2)
return
}
cfgPath := os.Args[2]
cfg := config.Parse(cfgPath)
c, err := client.New(cfg)
if err != nil {
slog.Error(fmt.Sprintf("Error when initializing client: %s", err.Error()))
}
logger = logger.With("root", cfg.Root)
slog.SetDefault(logger)
c.Execute()
}
func printVersion() {
fmt.Printf("Visor %s\n", util.GetVersion())
}
func main() {
if len(os.Args) < 2 {
incorrectArg()
}
switch os.Args[1] {
case "run":
runCfg()
break
case "version":
printVersion()
break
default:
incorrectArg()
}
}