...
1
16
17 package main
18
19 import (
20 "fmt"
21 "io"
22 "os"
23
24 kruntime "k8s.io/apimachinery/pkg/runtime"
25
26 flag "github.com/spf13/pflag"
27 "k8s.io/klog/v2"
28 )
29
30 var (
31 functionDest = flag.StringP("func-dest", "f", "-", "Output for swagger functions; '-' means stdout (default)")
32 typeSrc = flag.StringP("type-src", "s", "", "From where we are going to read the types")
33 verify = flag.BoolP("verify", "v", false, "Verifies if the given type-src file has documentation for every type")
34 )
35
36 func main() {
37 flag.Parse()
38
39 if *typeSrc == "" {
40 klog.Fatalf("Please define -s flag as it is the source file")
41 }
42
43 var funcOut io.Writer
44 if *functionDest == "-" {
45 funcOut = os.Stdout
46 } else {
47 file, err := os.Create(*functionDest)
48 if err != nil {
49 klog.Fatalf("Couldn't open %v: %v", *functionDest, err)
50 }
51 defer file.Close()
52 funcOut = file
53 }
54
55 docsForTypes := kruntime.ParseDocumentationFrom(*typeSrc)
56
57 if *verify {
58 rc, err := kruntime.VerifySwaggerDocsExist(docsForTypes, funcOut)
59 if err != nil {
60 fmt.Fprintf(os.Stderr, "Error in verification process: %s\n", err)
61 }
62 os.Exit(rc)
63 }
64
65 if len(docsForTypes) > 0 {
66 if err := kruntime.WriteSwaggerDocFunc(docsForTypes, funcOut); err != nil {
67 fmt.Fprintf(os.Stderr, "Error when writing swagger documentation functions: %s\n", err)
68 os.Exit(-1)
69 }
70 }
71 }
72
View as plain text