-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
44 lines (40 loc) · 758 Bytes
/
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
package main
import (
"flag"
"fmt"
"github.com/TBXark/github-backup/config"
"github.com/robfig/cron/v3"
"log"
)
var (
BuildVersion = "dev"
)
func main() {
c := flag.String("config", "config.json", "config file")
v := flag.Bool("version", false, "show version")
h := flag.Bool("help", false, "show help")
flag.Parse()
if *v {
fmt.Println(BuildVersion)
return
}
if *h {
flag.Usage()
return
}
conf, err := config.LoadConfig(*c)
if err != nil {
log.Fatalf("load config error: %s", err.Error())
}
syncTask := NewTask(conf)
if conf.Cron != "" {
task := cron.New()
_, e := task.AddFunc(conf.Cron, syncTask.Run)
if e != nil {
log.Fatalf("add cron task error: %s", e.Error())
}
task.Run()
} else {
syncTask.Run()
}
}