forked from gobackup/gobackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
78 lines (67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"os"
"github.com/huacnlee/gobackup/config"
"github.com/huacnlee/gobackup/model"
"github.com/urfave/cli"
)
const (
usage = "Easy full stack backup operations on UNIX-like systems"
)
var (
modelName = ""
configFile = ""
version = "master"
)
func main() {
app := cli.NewApp()
app.Version = version
app.Name = "gobackup"
app.Usage = usage
app.Commands = []cli.Command{
{
Name: "perform",
Flags: []cli.Flag{
cli.StringFlag{
Name: "model, m",
Usage: "Model name that you want execute",
Destination: &modelName,
},
cli.StringFlag{
Name: "config, c",
Usage: "Special a config file",
Destination: &configFile,
},
},
Action: func(c *cli.Context) error {
config.Init(configFile)
if len(modelName) == 0 {
performAll()
} else {
performOne(modelName)
}
return nil
},
},
}
app.Run(os.Args)
}
func performAll() {
for _, modelConfig := range config.Models {
m := model.Model{
Config: modelConfig,
}
m.Perform()
}
}
func performOne(modelName string) {
for _, modelConfig := range config.Models {
if modelConfig.Name == modelName {
m := model.Model{
Config: modelConfig,
}
m.Perform()
return
}
}
}