-
-
Notifications
You must be signed in to change notification settings - Fork 559
/
main.go
143 lines (117 loc) Β· 2.32 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"go/build"
"os"
"strings"
"flag"
goa "goa.design/goa/v3/pkg"
)
func main() {
var (
cmd string
path string
offset int
)
{
if len(os.Args) == 1 {
usage()
}
switch os.Args[1] {
case "version":
fmt.Println("Goa version " + goa.Version())
os.Exit(0)
case "gen", "example":
if len(os.Args) == 2 {
usage()
}
cmd = os.Args[1]
path = os.Args[2]
offset = 2
default:
usage()
}
}
var (
output = "."
debug bool
)
if len(os.Args) > offset+1 {
var (
fset = flag.NewFlagSet("default", flag.ExitOnError)
o = fset.String("o", "", "output `directory`")
out = fset.String("output", output, "output `directory`")
)
fset.BoolVar(&debug, "debug", false, "Print debug information")
fset.Usage = usage
fset.Parse(os.Args[offset+1:])
output = *o
if output == "" {
output = *out
}
}
gen(cmd, path, output, debug)
}
// help with tests
var (
usage = help
gen = generate
)
func generate(cmd, path, output string, debug bool) {
var (
files []string
err error
tmp *Generator
)
if _, err = build.Import(path, ".", 0); err != nil {
goto fail
}
tmp = NewGenerator(cmd, path, output)
if !debug {
defer tmp.Remove()
}
if err = tmp.Write(debug); err != nil {
goto fail
}
if err = tmp.Compile(); err != nil {
goto fail
}
if files, err = tmp.Run(); err != nil {
goto fail
}
fmt.Println(strings.Join(files, "\n"))
return
fail:
fmt.Fprintln(os.Stderr, err.Error())
if !debug && tmp != nil {
tmp.Remove()
}
os.Exit(1)
}
func help() {
fmt.Fprint(os.Stderr, `goa is the code generation tool for the goa framework.
Learn more at https://goa.design.
Usage:
goa gen PACKAGE [--out DIRECTORY] [--debug]
goa example PACKAGE [--out DIRECTORY] [--debug]
goa version
Commands:
gen
Generate service interfaces, endpoints, transport code and OpenAPI spec.
example
Generate example server and client tool.
version
Print version information (exclusive with other flags and commands).
Args:
PACKAGE
Go import path to design package
Flags:
-o, -output DIRECTORY
output directory, defaults to the current working directory
-debug
Print debug information (mainly intended for goa developers)
Example:
goa gen goa.design/cellar/design -o gendir
`)
os.Exit(1)
}