...
1
16
17 package args
18
19 import (
20 "fmt"
21
22 "github.com/spf13/pflag"
23 )
24
25 type Args struct {
26 OutputDir string
27 OutputPkg string
28 OutputFile string
29
30 GoHeaderFile string
31
32
33
34
35 ReportFilename string
36 }
37
38
39
40 func New() *Args {
41 args := &Args{}
42
43
44 args.ReportFilename = "-"
45
46 return args
47 }
48
49
50 func (args *Args) AddFlags(fs *pflag.FlagSet) {
51 fs.StringVar(&args.OutputDir, "output-dir", "",
52 "the base directory under which to generate results")
53 fs.StringVar(&args.OutputPkg, "output-pkg", "",
54 "the base Go import-path under which to generate results")
55 fs.StringVar(&args.OutputFile, "output-file", "generated.openapi.go",
56 "the name of the file to be generated")
57 fs.StringVar(&args.GoHeaderFile, "go-header-file", "",
58 "the path to a file containing boilerplate header text; the string \"YEAR\" will be replaced with the current 4-digit year")
59 fs.StringVarP(&args.ReportFilename, "report-filename", "r", args.ReportFilename,
60 "Name of report file used by API linter to print API violations. Default \"-\" stands for standard output. NOTE that if valid filename other than \"-\" is specified, API linter won't return error on detected API violations. This allows further check of existing API violations without stopping the OpenAPI generation toolchain.")
61 }
62
63
64 func (args *Args) Validate() error {
65 if len(args.OutputDir) == 0 {
66 return fmt.Errorf("--output-dir must be specified")
67 }
68 if len(args.OutputPkg) == 0 {
69 return fmt.Errorf("--output-pkg must be specified")
70 }
71 if len(args.OutputFile) == 0 {
72 return fmt.Errorf("--output-file must be specified")
73 }
74 if len(args.ReportFilename) == 0 {
75 return fmt.Errorf("--report-filename must be specified (use \"-\" for stdout)")
76 }
77 return nil
78 }
79
View as plain text