-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 1.38 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
package main
import (
"log"
"net/http"
"os"
"path/filepath"
"warden/command"
"warden/internal/api/thunderstore"
"warden/internal/config"
"warden/internal/data/file"
"warden/internal/data/repo"
"warden/internal/service"
"github.com/mitchellh/go-homedir"
)
func main() {
// Load in the config
home, err := homedir.Dir()
if err != nil {
log.Fatal(err)
}
cfg, err := config.Load(home)
if err != nil {
log.Fatal(err.Error())
}
// Open database and initialize tables if they don't already exist
db, err := repo.OpenDatabase(filepath.Join(home, ".warden.db"))
if err != nil {
log.Fatal(err.Error())
}
repo.CreateModsTable(db)
repo.CreateFrameworksTable(db)
// Initialize and injection dependencies into commands
mr := repo.NewModsRepo(db)
fr := repo.NewFrameworksRepo(db)
ts := thunderstore.New(&http.Client{})
fm := file.NewManager(&http.Client{}, cfg.ValheimDirectory)
ms := service.NewModService(mr, fm, ts, os.Stdin)
fs := service.NewFrameworkService(fr, fm, ts, os.Stdin)
ss := service.NewServerService(*cfg)
// Register commands
listCmd := command.NewListCommand(ms)
addCmd := command.NewAddCommand(fs, ms)
removeCmd := command.NewRemoveCommand(fs, ms)
updateCmd := command.NewUpdateCommand(fs, ms)
configCmd := command.NewConfigCommand(*cfg)
startCmd := command.NewStartCommand(ss)
command.Execute(listCmd, addCmd, removeCmd, updateCmd, configCmd, startCmd)
}