-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
87 lines (76 loc) · 1.76 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
package main
import (
"embed"
"fmt"
"os"
"github.com/tech-thinker/gozen/cmd"
"github.com/tech-thinker/gozen/cmd/helper"
"github.com/tech-thinker/gozen/models"
"github.com/urfave/cli/v2"
)
var (
AppVersion = "v0.0.0"
CommitHash = "unknown"
BuildDate = "unknown"
)
//go:embed templates/*
var templatesFS embed.FS
func main() {
// Declaring flags
var packageName string
var outputDir string
var driver string
// Initialize common helper
helper := helper.NewCommonHelper(templatesFS)
clientApp := cli.NewApp()
clientApp.Name = "gozen"
clientApp.Version = AppVersion
clientApp.Commands = []*cli.Command{
{
Name: "create",
Usage: "Create new Projects.",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pkg",
Aliases: []string{"p"},
Value: "",
Usage: "Package name for new project.",
Destination: &packageName,
},
&cli.StringFlag{
Name: "output",
Aliases: []string{"o"},
Value: ".",
Usage: "Output directory for new project.",
Destination: &outputDir,
},
&cli.StringFlag{
Name: "driver",
Aliases: []string{"d"},
Value: "sqlite",
Usage: "Database driver for new project. eg. [sqlite, mysql, postgres]",
Destination: &driver,
},
},
Action: func(ctx *cli.Context) error {
project := models.Project{
AppName: ctx.Args().Get(0),
PackageName: packageName,
Driver: driver,
WorkingDir: outputDir,
}
err := project.Validate()
if err != nil {
fmt.Println(err)
return nil
}
project.AutoFixes()
app := cmd.NewAppCmd(project, helper)
return app.CreateApp()
},
},
}
if err := clientApp.Run(os.Args); err != nil {
panic(err)
}
}