-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (60 loc) · 1.75 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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/fanchann/go-starter/app"
"github.com/fanchann/go-starter/helpers"
)
var (
logo = `
┌─┐┌─┐ ┌─┐┌┬┐┌─┐┬─┐┌┬┐┌─┐┬─┐
│ ┬│ │───└─┐ │ ├─┤├┬┘ │ ├┤ ├┬┘
└─┘└─┘ └─┘ ┴ ┴ ┴┴└─ ┴ └─┘┴└─
`
showHelp = flag.Bool("help", false, "show help message")
starterFile = flag.String("f", "starter.yaml", "starter configuration file")
starterDefaultConfiguration = map[string]interface{}{
"version": "1",
"package": "your-name-package",
"database": "mysql",
}
)
func init() {
flag.Parse()
}
func main() {
fmt.Printf("%v \n", logo)
newArgs := os.Args[1:]
if len(newArgs) > 0 {
command := newArgs[0]
switch command {
case "new":
log.Print("Success generate starter.yaml \n")
generateConfiguration()
return
case "help":
printHelpMessage()
return
}
}
processStarterApp(starterFile)
}
func generateConfiguration() error {
return helpers.NewYamlWriter(starterDefaultConfiguration, ".", "starter.yaml")
}
func processStarterApp(appConfigFile *string) {
starterConfiguration := helpers.NewStarterYamlParser(*appConfigFile)
err := app.GoStarter(app.Options{AppName: starterConfiguration.Package, Driver: starterConfiguration.Database})
helpers.ErrorWithLog(err)
}
func printHelpMessage() {
fmt.Println("Usage: go-starter [OPTIONS]")
fmt.Println("\nOptions:")
flag.PrintDefaults()
fmt.Println("\nExamples:")
fmt.Println(" go-starter new Generate configuration file")
fmt.Println(" go-starter Run the application")
fmt.Println(" go-starter -f=configuration.yaml [default: starter.yaml] Specify a custom configuration file")
}