-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.go
67 lines (60 loc) · 1.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
package main
import (
"log"
"os"
"github.com/urfave/cli"
)
var version = "v1.0.0"
var flags = []cli.Flag{
cli.StringFlag{
Name: "module-path",
Value: "",
Usage: "goas will search @comment under the module",
},
cli.StringFlag{
Name: "main-file-path",
Value: "",
Usage: "goas will start to search @comment from this main file",
},
cli.StringFlag{
Name: "handler-path",
Value: "",
Usage: "goas only search handleFunc comments under the path",
},
cli.StringFlag{
Name: "output",
Value: "oas.json",
Usage: "output file",
},
cli.BoolFlag{
Name: "debug",
Usage: "show debug message",
},
}
func action(c *cli.Context) error {
p, err := newParser(c.GlobalString("module-path"), c.GlobalString("main-file-path"), c.GlobalString("handler-path"), c.GlobalBool("debug"))
if err != nil {
return err
}
// fmt.Printf("%+v\n", p)
return p.CreateOASFile(c.GlobalString("output"))
}
func main() {
app := cli.NewApp()
app.Name = "goas"
app.Usage = ""
// app.UsageText = "goas [options]"
app.Version = version
app.Copyright = "(c) 2018 mikun800527@gmail.com"
app.HideHelp = true
app.OnUsageError = func(c *cli.Context, err error, isSubcommand bool) error {
cli.ShowAppHelp(c)
return nil
}
app.Flags = flags
app.Action = action
err := app.Run(os.Args)
if err != nil {
log.Fatal("Error: ", err)
}
}