-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
78 lines (57 loc) · 1.8 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
// 🚀 Optical is a CLI tool that generates a Go Fiber project template. It is inspired by express-generator, a tool that generates a Node.js project template for the Express.js framework.
// 🚀 Optical generates a project structure with a basic setup for a Go Fiber API project, including a main.go file, handlers, middleware, models, routes, services, and a config package.
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"github.com/tuhinexe/optical/lib/generator"
"github.com/tuhinexe/optical/lib/helper"
)
var (
version = "1.1.0"
logo = `
_______ __ __ __
| |.-----.| |_|__|.----.---.-.| |
| - || _ || _| || __| _ || |
|_______|| __||____|__||____|___._||__|
|__| `
)
func main() {
createFlag := flag.Bool("create", false, "Creates a new Optical Project")
versionFlag := flag.Bool("version", false, "Print the version of Optical CLI")
flag.Bool("help", false, "Help for Optical CLI")
flag.Usage = func() {
helper.PrintFlags()
}
flag.Parse()
if *versionFlag {
helper.PrintVersion(version)
return
}
if *createFlag {
fmt.Println(logo)
helper.PrintVersion(version)
form, prompts := helper.CreateForm()
err := form.Run()
if err != nil {
fmt.Println("There is an error creating your project")
return
}
if prompts.ProjectName == "./" || prompts.ProjectName == "" {
prompts.ProjectName = filepath.Base(helper.GetCurrentDirectory())
}
projectErr := generator.GenerateProject(prompts.ProjectName, ".", prompts.GhUserName, prompts.HasAir)
if projectErr != nil {
fmt.Printf("❗Error generating project: %v\n", projectErr)
os.Exit(1)
}
helper.PrintSuccessMsg(prompts.ProjectName)
} else {
fmt.Println(logo)
helper.PrintVersion(version)
flag.Usage()
os.Exit(1)
}
}