diff --git a/cmd/crd.go b/cmd/crd.go index 1d0abb7..9e7a425 100644 --- a/cmd/crd.go +++ b/cmd/crd.go @@ -78,6 +78,11 @@ func runGenerate(_ *cobra.Command, _ []string) error { } var w io.WriteCloser + defer func() { + if err := w.Close(); err != nil { + _, _ = fmt.Fprintf(os.Stderr, "failed to close output file: %s", err.Error()) + } + }() if crdArgs.format == FormatHTML { if crdArgs.stdOut { @@ -87,12 +92,6 @@ func runGenerate(_ *cobra.Command, _ []string) error { if err != nil { return fmt.Errorf("failed to create output file: %w", err) } - - defer func() { - if err := w.Close(); err != nil { - _, _ = fmt.Fprintf(os.Stderr, "failed to close output file: %s", err.Error()) - } - }() } return pkg.RenderContent(w, crds, crdArgs.comments, crdArgs.minimal) diff --git a/pkg/create_html_output.go b/pkg/create_html_output.go index 34bbd66..d72de1a 100644 --- a/pkg/create_html_output.go +++ b/pkg/create_html_output.go @@ -3,7 +3,6 @@ package pkg import ( "bytes" "embed" - "errors" "fmt" "html/template" "io" @@ -65,12 +64,6 @@ func LoadTemplates() error { // RenderContent creates an HTML website from the CRD content. func RenderContent(w io.WriteCloser, crds []*SchemaType, comments, minimal bool) (err error) { - defer func() { - if cerr := w.Close(); cerr != nil { - err = errors.Join(err, cerr) - } - }() - allViews := make([]ViewPage, 0, len(crds)) for _, crd := range crds { diff --git a/pkg/generate.go b/pkg/generate.go index 06b0890..92f812a 100644 --- a/pkg/generate.go +++ b/pkg/generate.go @@ -1,7 +1,6 @@ package pkg import ( - "errors" "fmt" "io" "regexp" @@ -19,12 +18,6 @@ var RootRequiredFields = []string{"apiVersion", "kind", "spec", "metadata"} // Generate takes a CRD content and path, and outputs. func Generate(crd *SchemaType, w io.WriteCloser, enableComments, minimal, skipRandom bool) (err error) { - defer func() { - if cerr := w.Close(); cerr != nil { - err = errors.Join(err, cerr) - } - }() - parser := NewParser(crd.Group, crd.Kind, enableComments, minimal, skipRandom) for i, version := range crd.Versions { if err := parser.ParseProperties(version.Name, w, version.Schema.Properties); err != nil {