-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
78 lines (62 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"io"
"os"
"path/filepath"
"github.com/jsphbtst/babelfish/cmd"
"github.com/jsphbtst/babelfish/pkg/data"
"github.com/jsphbtst/babelfish/pkg/files"
"github.com/jsphbtst/babelfish/pkg/types"
)
func main() {
homeDir, err := os.UserHomeDir()
if err != nil {
panic(err)
}
rootDir := filepath.Join(homeDir, ".babelfish")
err = os.MkdirAll(rootDir, 0755)
if err != nil {
panic(err)
}
cmd.InitRootDir(rootDir)
data.InitializeDirFiles(rootDir)
// TODO: refactor this part later
keyFile, err := os.OpenFile(
filepath.Join(rootDir, "openai-access-key"),
os.O_RDWR|os.O_CREATE,
0666,
)
if err != nil {
panic(err)
}
defer keyFile.Close()
openAiBytes, err := io.ReadAll(keyFile)
if err != nil {
panic(err)
}
openAiApiKey := string(openAiBytes)
cmd.InitOpenAiKey(openAiApiKey)
// Configs file
var configs types.Configs
err = files.Parse(filepath.Join(rootDir, "configs.json"), &configs)
if err != nil {
panic(err)
}
cmd.InitConfigs(&configs)
// History File
var history types.HistoryJson
err = files.Parse(filepath.Join(rootDir, "history.json"), &history)
if err != nil {
panic(err)
}
cmd.InitHistory(&history)
// Breakdowns File
var breakdowns types.BreakdownJson
err = files.Parse(filepath.Join(rootDir, "breakdowns.json"), &breakdowns)
if err != nil {
panic(err)
}
cmd.InitBreakdowns(&breakdowns)
// Begin CLI
cmd.Execute()
}