-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroquette.go
87 lines (72 loc) · 1.8 KB
/
roquette.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
79
80
81
82
83
84
85
86
87
package main
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/estebgonza/roquette/roquettor"
"github.com/urfave/cli"
)
const (
appName string = "Roquette"
appDescription string = "Stress your database"
appVersion string = "0.1"
defaultPlanFile string = "plan.json"
defaultDatabaseFile string = "database.json"
)
const helpTemplate = `
Usage: {{.HelpName}} [command]
{{if .Commands}}Commands:
{{range .Commands}}{{if not .HideHelp}}{{join .Names ", "}}{{ "\t"}}{{.Usage}}{{ "\n" }}{{end}}{{end}}{{end}}
`
func main() {
cli.AppHelpTemplate = fmt.Sprintf(helpTemplate)
app := cli.NewApp()
app.Name = appName
app.Usage = appDescription
app.Version = appVersion
app.Commands = []cli.Command{
{
Name: "run",
Usage: "Execute your plan on specified database",
Action: run,
},
{
Name: "init",
Usage: "Initialize Roquette files template",
},
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func run(c *cli.Context) error {
var jsonFile *os.File
var byteValue []byte
// Plan
// TODO: Improve 'json to struct' operations
var p roquettor.Plan
jsonFile, err := os.Open(defaultPlanFile)
if err != nil {
return errors.New("No plan.json found, please read https://github.com/estebgonza/roquette")
}
byteValue, _ = ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &p)
// Database
// TODO: Improve 'json to struct' operations
var d roquettor.Database
jsonFile, err = os.Open(defaultDatabaseFile)
if err != nil {
return errors.New("No database.json found, please read https://github.com/estebgonza/roquette")
}
byteValue, _ = ioutil.ReadAll(jsonFile)
json.Unmarshal(byteValue, &d)
if d.Connection.Db == "" {
d.Connection.Db = "default"
}
// Execute plan on specified database
return roquettor.Execute(&d, &p)
}