-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
73 lines (59 loc) · 1.49 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
package main
import (
"fmt"
"github.com/fatih/color"
"github.com/urfave/cli"
"log"
"os"
"path/filepath"
)
var dataDir = filepath.Join(homeDir(), ".mal")
var (
AppConfigFile = filepath.Join(dataDir, "appConfig.json")
MalCredentialsFile = filepath.Join(dataDir, "malCred.dat")
MalCacheFile = filepath.Join(dataDir, "malCache.xml")
MalStatsCacheFile = filepath.Join(dataDir, "malStats.xml")
MalConfigFile = filepath.Join(dataDir, "malConfig.json")
AniListCredsFile = filepath.Join(dataDir, "aniListCreds.json")
AniListUserFile = filepath.Join(dataDir, "aniListUser.json")
AniListCacheFile = filepath.Join(dataDir, "aniListCache.json")
)
type Mode uint
const (
MalMode Mode = iota
AniListMode
)
type AppConfig struct {
Mode Mode
}
func main() {
checkDataDir()
appCfg := AppConfig{Mode: AniListMode}
LoadJsonFile(AppConfigFile, &appCfg)
app := cli.NewApp()
app.Name = "mal"
app.Usage = "App for managing your MAL"
app.Version = "4ever in beta"
switch appCfg.Mode {
case MalMode:
runApp(MalApp(app))
case AniListMode:
runApp(AniListApp(app))
}
}
func checkDataDir() {
if err := os.Mkdir(dataDir, os.ModePerm); err == nil {
log.Printf("Created cache directory at %s", dataDir)
} else if !os.IsExist(err) {
log.Printf("Error creating cache directory (%s): %v", dataDir, err)
}
}
func runApp(app *cli.App) {
if err := app.Run(os.Args); err != nil {
exitWithError(err)
}
}
func exitWithError(err error) {
fmt.Fprintf(color.Output, "Error: %v\n", err)
os.Exit(1)
}