/
confur.go
69 lines (62 loc) · 1.4 KB
/
confur.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
package main
import (
"flag"
"fmt"
"github.com/confur-me/confur-api/api/migrator"
"github.com/confur-me/confur-api/lib/config"
"github.com/confur-me/confur-api/server"
//"github.com/confur-me/confur-api/test/fixtures"
"os"
)
var configFile *string
func init() {
const (
help_description = "print this help"
config_description = "path to config file"
usage = `
Usage:
confur -config=/path/to/config.yml start : start server
confur -config=/path/to/config.yml db:drop : Drop database
confur -config=/path/to/config.yml db:create : Create database
confur -config=/path/to/config.yml db:migrate : Migrate database
confur -config=/path/to/config.yml fixtures:seed : Seed test data
`
)
flag.Bool("h", false, help_description)
configFile = flag.String("c", "confur.yml", config_description)
flag.Usage = func() {
fmt.Println("Options:")
flag.PrintDefaults()
fmt.Print(usage)
os.Exit(0)
}
}
func main() {
args := parseFlags()
if err := config.Read(*configFile); err != nil {
os.Exit(0)
}
switch args[0] {
case "start":
app := server.Application{}
app.Run()
case "db:migrate":
migrator.DbMigrate()
case "db:drop":
migrator.DbDrop()
case "db:create":
migrator.DbCreate()
case "fixtures:seed":
//fixtures.Seed()
default:
flag.Usage()
}
}
func parseFlags() []string {
flag.Parse()
args := flag.Args()
if len(args) == 0 {
flag.Usage()
}
return args
}