-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (51 loc) · 1.25 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
package main
import (
"fmt"
"github.com/urfave/cli/v2"
"history-engine/engine/jobs"
"history-engine/engine/setting"
"history-engine/engine/utils"
"history-engine/engine/web"
"log"
"os"
"path/filepath"
"runtime"
"time"
)
var buildVersion = "dev-master"
func main() {
app := cli.NewApp()
app.Name = "history engine"
app.Usage = "history engine"
app.Description = "history engine"
app.Before = loadSetting
app.Commands = []*cli.Command{web.Web, jobs.Jobs}
app.Version = fmt.Sprintf("%s, build with: %s, time: %s", buildVersion, runtime.Version(), time.Now().Format(time.RFC3339))
app.DefaultCommand = web.Web.Name
app.Flags = append(app.Flags, []cli.Flag{
&cli.StringFlag{
Name: "config, c",
Aliases: []string{"c"},
Usage: "Custom configuration file path",
},
}...)
if err := app.Run(os.Args); err != nil {
log.Fatalf("Failed to run app with %s: %v", os.Args, err)
}
}
func loadSetting(c *cli.Context) error {
name := "setting.toml"
file := c.String("config")
if file == "" {
pwd, _ := os.Executable()
file = filepath.Dir(pwd) + "/" + name
if !utils.FileExist(file) {
pwd, _ := os.Getwd()
file = pwd + "/" + name
}
}
if !utils.FileExist(file) {
log.Fatalln("setting file not exist")
}
return setting.Load(file)
}