forked from LordPax/aicli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (63 loc) · 1.46 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
package main
import (
"fmt"
"os"
"github.com/LordPax/aicli/commands"
"github.com/LordPax/aicli/config"
"github.com/LordPax/aicli/lang"
"github.com/LordPax/aicli/utils"
cli "github.com/urfave/cli/v2"
ini "gopkg.in/ini.v1"
)
func main() {
if err := config.InitConfig(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
log, err := utils.GetLog()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
defer log.Close()
config.CONFIG_INI, err = ini.Load(config.CONFIG_FILE)
if err != nil {
log.PrintfErr("%v\n", err)
os.Exit(1)
}
l := lang.GetLocalize()
l.SetLang(os.Getenv("LANG"))
l.AddStrings(&lang.EN_STRINGS, "en_US.UTF-8", "en_GB.UTF-8", "en")
l.AddStrings(&lang.FR_STRINGS, "fr_FR.UTF-8", "fr_CA.UTF-8", "fr")
app := cli.NewApp()
app.Name = config.NAME
app.Usage = l.Get("usage")
app.Version = config.VERSION
app.Action = commands.MainAction
app.Flags = commands.MainFlags()
textCmd, err := commands.TextCommand()
if err != nil {
log.PrintfErr("%v\n", err)
os.Exit(1)
}
translateCmd, err := commands.TranslateCommand()
if err != nil {
log.PrintfErr("%v\n", err)
os.Exit(1)
}
imageCmd, err := commands.ImageCommand()
if err != nil {
log.PrintfErr("%v\n", err)
os.Exit(1)
}
app.Commands = []*cli.Command{
textCmd,
translateCmd,
imageCmd,
// TODO : add command for audio
}
if err := app.Run(os.Args); err != nil {
log.PrintfErr("%v\n", err)
}
_ = utils.RmTmpDir()
}