func main()

in cmd/generator/main.go [78:124]


func main() {
	flag.StringVar(&sourceFile, "source", defaultSourceFile, "source file to parse")
	flag.StringVar(&destinationFile, "destination", defaultDestinationFile, "destination file to save the result")
	flag.StringVar(&defFile, "def-file", "", "destination file where to save the definition result")
	flag.StringVar(&version, "version", "", "ECE version")
	flag.Parse()

	b, err := os.ReadFile(sourceFile)
	exitOnError(err, codeCannotOpenFile)

	if len(b) == 0 {
		exitOnError(errFileMustNotBeEmpty, codeFileMustNotBeEmpty)
	}

	var cloudSpec *spec.Swagger
	if err := json.Unmarshal(b, &cloudSpec); err != nil {
		exitOnError(errFailedUnmarshalingSpec, codeFailedUnmarshalingSpec)
	}
	cloudSpec.Info.Version, cloudSpec.Info.Title = "v1", "rest"

	commandFile, err := os.Create(defFile)
	if err != nil {
		println(err.Error())
		commandFile = os.Stdout
	}
	defer commandFile.Close()

	cloudspec.GetCommands(cloudSpec, commandFile, version)

	exitOnError(
		genVersionFile(filepath.Join("pkg", "api", "version.go"), version),
		codeFailedGeneratingVersionFile,
	)

	// Modifies the spec mainly to make some properties of the swagger spec
	// nullable or ommitable when they're empty to make it fully compatible
	// for Go programatic consumption.
	cloudspec.Modify(cloudSpec)

	f, err := os.Create(destinationFile)
	exitOnError(err, codeFailedCreatingDestinationFile)
	defer f.Close()

	enc := json.NewEncoder(f)
	enc.SetIndent("", "  ")
	exitOnError(enc.Encode(cloudSpec), codeFailedEncodingSpec)
}