-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgin-scaffold.go
62 lines (51 loc) · 1.04 KB
/
gin-scaffold.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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/dcu/gin-scaffold/command"
)
func printUsageAndExit() {
fmt.Printf("Gin Scaffold\n")
for commandName, command := range command.Commands {
fmt.Printf("\nCommand `%s`:\n\n", commandName)
command.Help()
}
os.Exit(0)
}
func checkGOPATH() {
if os.Getenv("GOPATH") == "" {
fmt.Printf("$GOPATH is not defined. Exiting.\n")
os.Exit(2)
}
wd, _ := os.Getwd()
wd = filepath.ToSlash(wd)
found := false
for _, p := range filepath.SplitList(os.Getenv("GOPATH")) {
if strings.HasPrefix(strings.ToLower(wd), strings.ToLower(filepath.ToSlash(p))) {
found = true
break
}
}
if !found {
fmt.Printf("%s is not in the $GOPATH. Exiting.\n", wd)
os.Exit(3)
}
}
func main() {
checkGOPATH()
if len(os.Args) < 2 {
printUsageAndExit()
}
commandName := os.Args[1]
commandArgs := []string{}
if len(os.Args) > 2 {
commandArgs = os.Args[2:]
}
command := command.FindCommand(commandName)
if command == nil {
printUsageAndExit()
}
command.Execute(commandArgs)
}