-
Notifications
You must be signed in to change notification settings - Fork 128
/
main.go
63 lines (53 loc) · 2.06 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
package main
import (
"flag"
"strings"
log "github.com/sirupsen/logrus"
"github.com/yvasiyarov/swagger/generator"
)
var apiPackage = flag.String("apiPackage", "", "The package that implements the API controllers, relative to $GOPATH/src")
var mainApiFile = flag.String("mainApiFile", "", "The file that contains the general API annotations, relative to $GOPATH/src")
var outputFormat = flag.String("format", "go", "Output format type for the generated files: "+generator.AVAILABLE_FORMATS)
var outputSpec = flag.String("output", "", "Output (path) for the generated file(s)")
var controllerClass = flag.String("controllerClass", "", "Speed up parsing by specifying which receiver objects have the controller methods")
var ignore = flag.String("ignore", "^$", "Ignore packages that satisfy this match")
var contentsTable = flag.Bool("contentsTable", true, "Generate the section Table of Contents")
var models = flag.Bool("models", true, "Generate the section models if any defined")
var vendoringPath = flag.String("vendoringPath", "", "Override default vendor directory")
var disableVendoring = flag.Bool("disableVendoring", false, "Disable vendor dir usage")
var enableDebug = flag.Bool("enableDebug", false, "Enable debug log output")
func init() {
flag.Parse()
if *enableDebug {
log.SetLevel(log.DebugLevel)
log.Info("Debug logging enabled")
}
}
func main() {
if *mainApiFile == "" {
*mainApiFile = *apiPackage + "/main.go"
log.Debugf("Using '%v' as main API file", *mainApiFile)
}
if *apiPackage == "" {
flag.PrintDefaults()
return
}
// Get rid of trailing /
*vendoringPath = strings.TrimSuffix(*vendoringPath, "/")
params := generator.Params{
ApiPackage: *apiPackage,
MainApiFile: *mainApiFile,
OutputFormat: *outputFormat,
OutputSpec: *outputSpec,
ControllerClass: *controllerClass,
Ignore: *ignore,
ContentsTable: *contentsTable,
Models: *models,
VendoringPath: *vendoringPath,
DisableVendoring: *disableVendoring,
}
err := generator.Run(params)
if err != nil {
log.Fatal(err.Error())
}
}