-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (67 loc) · 1.67 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
package main
import (
"os"
"path/filepath"
"github.com/nobbmaestro/lazyhis/cmd"
"github.com/nobbmaestro/lazyhis/pkg/config"
"github.com/nobbmaestro/lazyhis/pkg/db"
"github.com/nobbmaestro/lazyhis/pkg/domain/model"
"github.com/nobbmaestro/lazyhis/pkg/domain/repository"
"github.com/nobbmaestro/lazyhis/pkg/domain/service"
"github.com/nobbmaestro/lazyhis/pkg/log"
"github.com/nobbmaestro/lazyhis/pkg/registry"
)
var (
version = "dev"
commit = "unknown"
date = "unknown"
)
var (
dbPath = filepath.Join(os.Getenv("HOME"), ".lazyhis.db")
confPath = filepath.Join(os.Getenv("HOME"), ".config", "lazyhis", "lazyhis.yml")
)
func main() {
cfg := config.ReadUserConfig(confPath)
logger, err := log.New(cfg.Log)
if err != nil {
return
}
defer logger.Close()
database, err := db.New(
dbPath,
db.WithLogger(db.DefaultLogger()),
db.WithForeignKeysOn(),
db.WithAutoMigrate(
model.History{},
model.Command{},
model.Session{},
model.Path{},
),
)
if err != nil {
return
}
historyService := service.NewHistoryService(
&service.RepositoryProvider{
CommandRepo: repository.NewCommandRepository(database),
HistoryRepo: repository.NewHistoryRepository(database),
PathRepo: repository.NewPathRepository(database),
SessionRepo: repository.NewSessionRepository(database),
},
&cfg.Db,
logger.Logger,
)
reg := registry.NewRegistry(
registry.WithConfig(cfg),
registry.WithConfigPath(confPath),
registry.WithLogger(logger.Logger),
registry.WithService(historyService),
)
cmd.SetContext(reg.Context)
cmd.SetVersionInfo(version, commit, date)
err = cmd.Execute()
if err != nil {
logger.Logger.Error(err.Error())
os.Exit(1)
}
}