-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
164 lines (159 loc) · 3.87 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"os"
"github.com/urfave/cli"
"github.com/snippetor/bingo/command"
"sort"
)
func main() {
app := cli.NewApp()
app.Name = "bingo"
app.Usage = "A distributed, open source framework in Golang"
app.Author = "snippetor@163.com"
app.Version = "v1.0.0"
app.Commands = []cli.Command{
{
Name: "init",
Aliases: []string{"i"},
Usage: "init go project with bingo framework",
Action: func(c *cli.Context) error {
if c.NArg() > 0 {
command.Init(c.Args()[0])
} else {
command.Init("")
}
return nil
},
},
{
Name: "debug",
Aliases: []string{"r"},
Usage: "debug the app with name and env",
UsageText: "bingo debug [app name] [env]",
Action: func(c *cli.Context) error {
if c.NArg() == 1 {
command.Debug(c.Args()[0], "")
} else if c.NArg() == 2 {
command.Debug(c.Args()[0], c.Args()[1])
} else {
cli.ShowCommandHelp(c, "debug")
}
return nil
},
},
{
Name: "new",
Aliases: []string{"n"},
Usage: "new a app config",
UsageText: "bingo new [app package] [app name] [env]",
Action: func(c *cli.Context) error {
if c.NArg() == 2 {
command.New(c.Args()[0], c.Args()[1], "")
} else if c.NArg() == 3 {
command.New(c.Args()[0], c.Args()[1], c.Args()[2])
} else {
cli.ShowCommandHelp(c, "new")
}
return nil
},
},
{
Name: "build",
Aliases: []string{"b"},
Usage: "build bingo app, if app name is * or app name and env is empty, build all app.",
UsageText: "bingo build [app name] [env] [options]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "p",
Usage: "build platform",
},
},
Action: func(c *cli.Context) error {
if c.NArg() == 0 {
command.Build("*", "", c.String("p"))
} else if c.NArg() == 1 {
command.Build(c.Args()[0], "", c.String("p"))
} else if c.NArg() == 2 {
command.Build(c.Args()[0], c.Args()[1], c.String("p"))
} else {
cli.ShowCommandHelp(c, "build")
}
return nil
},
},
{
Name: "pack",
Aliases: []string{"b"},
Usage: "pack bingo app, if app name is * or app name and env is empty, pack all app in one package.",
UsageText: "bingo publish [app name] [env]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "p",
Usage: "build platform",
},
},
Action: func(c *cli.Context) error {
if c.NArg() == 0 {
command.Pack("*", "", c.String("p"))
} else if c.NArg() == 1 {
command.Pack(c.Args()[0], "", c.String("p"))
} else if c.NArg() == 2 {
command.Pack(c.Args()[0], c.Args()[1], c.String("p"))
} else {
cli.ShowCommandHelp(c, "pack")
}
return nil
},
},
{
Name: "run",
Aliases: []string{"r"},
Usage: "run the app's executable file with name and env",
UsageText: "bingo run [app name] [env] [options]",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "b",
Usage: "running the app in background",
},
},
Action: func(c *cli.Context) error {
if c.NArg() == 1 {
command.Run(c.Args()[0], "", c.Bool("b"))
} else if c.NArg() == 2 {
command.Run(c.Args()[0], c.Args()[1], c.Bool("b"))
} else {
cli.ShowCommandHelp(c, "run")
}
return nil
},
},
{
Name: "pb",
Usage: "gen protobuf go file using gogofaster(https://github.com/gogo/protobuf)",
UsageText: "bingo pb [.proto dir]",
Flags: []cli.Flag{
cli.StringFlag{
Name: "d",
Usage: "output directory",
},
cli.BoolFlag{
Name: "s",
Usage: "output file into single directory",
},
},
Action: func(c *cli.Context) error {
if c.NArg() == 1 {
command.Pb(c.Args()[0], c.String("d"), c.Bool("s"))
} else {
cli.ShowCommandHelp(c, "pb")
}
return nil
},
},
}
sort.Sort(cli.CommandsByName(app.Commands))
err := app.Run(os.Args)
if err != nil {
panic(err)
}
}