MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / main

Function main

cmd/oapi-codegen/oapi-codegen.go:92–345  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90var noVCSVersionOverride string
91
92func main() {
93 flag.StringVar(&flagOutputFile, "o", "", "Where to output generated code, stdout is default.")
94 flag.BoolVar(&flagOldConfigStyle, "old-config-style", false, "Whether to use the older style config file format.")
95 flag.BoolVar(&flagOutputConfig, "output-config", false, "When true, outputs a configuration file for oapi-codegen using current settings.")
96 flag.StringVar(&flagConfigFile, "config", "", "A YAML config file that controls oapi-codegen behavior.")
97 flag.BoolVar(&flagPrintVersion, "version", false, "When specified, print version and exit.")
98 flag.StringVar(&flagPackageName, "package", "", "The package name for generated code.")
99 flag.BoolVar(&flagPrintUsage, "help", false, "Show this help and exit.")
100 flag.BoolVar(&flagPrintUsage, "h", false, "Same as -help.")
101
102 // All flags below are deprecated, and will be removed in a future release. Please do not
103 // update their behavior.
104 flag.StringVar(&flagGenerate, "generate", "types,client,server,spec",
105 `Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "gorilla", "spec", "skip-fmt", "skip-prune", "fiber", "iris", "std-http".`)
106 flag.StringVar(&flagIncludeTags, "include-tags", "", "Only include operations with the given tags. Comma-separated list of tags.")
107 flag.StringVar(&flagExcludeTags, "exclude-tags", "", "Exclude operations that are tagged with the given tags. Comma-separated list of tags.")
108 flag.StringVar(&flagIncludeOperationIDs, "include-operation-ids", "", "Only include operations with the given operation-ids. Comma-separated list of operation-ids.")
109 flag.StringVar(&flagExcludeOperationIDs, "exclude-operation-ids", "", "Exclude operations with the given operation-ids. Comma-separated list of operation-ids.")
110 flag.StringVar(&flagTemplatesDir, "templates", "", "Path to directory containing user templates.")
111 flag.StringVar(&flagImportMapping, "import-mapping", "", "A dict from the external reference to golang package path.")
112 flag.StringVar(&flagExcludeSchemas, "exclude-schemas", "", "A comma separated list of schemas which must be excluded from generation.")
113 flag.StringVar(&flagResponseTypeSuffix, "response-type-suffix", "", "The suffix used for responses types.")
114 flag.BoolVar(&flagAliasTypes, "alias-types", false, "Alias type declarations if possible.")
115
116 flag.Parse()
117
118 if flagPrintUsage {
119 flag.Usage()
120 os.Exit(0)
121 }
122
123 if flagPrintVersion {
124 bi, ok := debug.ReadBuildInfo()
125 if !ok {
126 fmt.Fprintln(os.Stderr, "error reading build info")
127 os.Exit(1)
128 }
129 fmt.Println(bi.Main.Path + "/cmd/oapi-codegen")
130 version := bi.Main.Version
131 if len(noVCSVersionOverride) > 0 {
132 version = noVCSVersionOverride
133 }
134 fmt.Println(version)
135 return
136 }
137
138 if flag.NArg() < 1 {
139 errExit("Please specify a path to a OpenAPI 3.0 spec file\n")
140 } else if flag.NArg() > 1 {
141 errExit("Only one OpenAPI 3.0 spec file is accepted and it must be the last CLI argument\n")
142 }
143
144 // We will try to infer whether the user has an old-style config, or a new
145 // style. Start with the command line argument. If it's true, we know it's
146 // old config style.
147 var oldConfigStyle *bool
148 if flagOldConfigStyle {
149 oldConfigStyle = &flagOldConfigStyle

Callers

nothing calls this directly

Calls 10

LoadSwaggerWithOverlayFunction · 0.92
GenerateFunction · 0.92
errExitFunction · 0.85
updateConfigFromFlagsFunction · 0.85
newConfigFromOldConfigFunction · 0.85
detectPackageNameFunction · 0.85
UpdateDefaultsMethod · 0.80
WarningsMethod · 0.80
ValidateMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected