diff --git a/doc/yaml_docs.go b/doc/yaml_docs.go index f5cd5a3..54c244d 100644 --- a/doc/yaml_docs.go +++ b/doc/yaml_docs.go @@ -130,7 +130,8 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) str fmt.Println(err) os.Exit(1) } - if _, err := fmt.Fprintf(w, string(final)); err != nil { + + if _, err := w.Write(final); err != nil { return err } return nil diff --git a/doc/yaml_docs_test.go b/doc/yaml_docs_test.go index fb969da..29e985e 100644 --- a/doc/yaml_docs_test.go +++ b/doc/yaml_docs_test.go @@ -106,3 +106,20 @@ func TestGenYamlTree(t *testing.T) { t.Fatalf("Expected file 'do.yaml' to exist") } } + +func BenchmarkGenYamlToFile(b *testing.B) { + c := initializeWithRootCmd() + file, err := ioutil.TempFile("", "") + if err != nil { + b.Fatal(err) + } + defer os.Remove(file.Name()) + defer file.Close() + + b.ResetTimer() + for i := 0; i < b.N; i++ { + if err := GenYaml(c, file); err != nil { + b.Fatal(err) + } + } +}