-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
46 lines (36 loc) · 1.24 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
// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
// SPDX-License-Identifier: BSD-2-Clause
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config cfg.yaml swagger.json
//go:generate go run main.go -add-header
package main
import (
"flag"
"fmt"
"os"
)
func main() {
addHeader := flag.Bool("add-header", false, "Add header to generated SDK.")
flag.Parse()
if *addHeader {
const headerFile = "copyright.txt"
const generatedFile = "./vcf/vcf.gen.go"
header, err := os.ReadFile(headerFile)
if err != nil {
fmt.Println(fmt.Errorf("error reading header file: %w", err))
os.Exit(1)
}
content, err := os.ReadFile(generatedFile)
if err != nil {
fmt.Println(fmt.Errorf("error reading generated file: %w", err))
os.Exit(1)
}
newContent := string(header) + string(content)
err = os.WriteFile(generatedFile, []byte(newContent), 0644)
if err != nil {
fmt.Println(fmt.Errorf("error writing to generated file: %w", err))
os.Exit(1)
}
fmt.Println("Header added to", generatedFile)
}
}