-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
75 lines (63 loc) · 1.48 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
package main
import (
"fmt"
"os"
"github.com/silentred/toolkit/cmd"
cli "gopkg.in/urfave/cli.v1"
)
var (
// Version of toolkit
Version = "v0.1.1"
// BuildTS is timestamp of build
BuildTS = "None"
// GitHash is commit version of build
GitHash = "None"
logo = `
_____ _ _ _ _
|_ _|__ ___ | | | _(_) |_
| |/ _ \ / _ \| | |/ / | __|
| | (_) | (_) | | <| | |_
|_|\___/ \___/|_|_|\_\_|\__|
Version: %s
GitHash: %s
BuildTS: %s
`
sourcePath string
)
func main() {
cli.VersionPrinter = versionPrinter
app := cli.NewApp()
app.Version = Version
app.Usage = "A toolkit of the Toolkit"
app.Commands = []cli.Command{
cli.Command{
Name: "new",
ShortName: "n",
Usage: "Create a new project",
UsageText: "For example: toolkit new app_name",
Flags: []cli.Flag{
cli.StringFlag{
Name: "src",
Usage: "Source path in the GOPATH. For example: github.com/silentred",
Value: "gitlab.alipay-inc.com/oceanbase-dba",
Destination: &sourcePath,
},
},
Action: NewProjectAction,
},
}
app.Run(os.Args)
}
func versionPrinter(ctx *cli.Context) {
fmt.Fprintf(ctx.App.Writer, logo, ctx.App.Version, GitHash, BuildTS)
cli.ShowAppHelp(ctx)
}
// NewProjectAction creates new project
func NewProjectAction(ctx *cli.Context) error {
appName := ctx.Args().First()
if appName == "" {
return fmt.Errorf("missing app_name as the first argument. try `toolkit new myapp`")
}
cmd.RunNew(sourcePath, appName)
return nil
}