Revert "Add the ability to specify a filePostpender in GenMarkdownTreeCustom (#1270)" (#1317)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
This reverts commit 23a6174c7f9d0c64a48e634054bdf6886fb7fbba.
authored by John McBride · committed by GitHub · parent 23a6174 · Browse files · 2 files·+4 added−46 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+4 added−46 removed
- other:+4 added−46 removed
Provenance
- Commit
ff416ad- Tree
5af6a6e- Author
John McBride <jpmmcbride@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
23a6174
2 files changed+4 added−46 removed
modified:doc/md_docs_test.go-39 removed
93 unmodified lines94 t.Fatalf("Expected file 'do.md' to exist")95 }96 }97 98-func TestGenMdTreeCustom(t *testing.T) {99- tmpdir, err := ioutil.TempDir("", "test-gen-md-tree")100- if err != nil {101- t.Fatalf("Failed to create tmpdir: %v", err)102- }103- defer os.RemoveAll(tmpdir)104-105- prepender := func(s string) string { return "Prepended" }106- postpender := func(s string) string { return "Postpended" }107- identity := func(s string) string { return s }108-109- if err := GenMarkdownTreeCustom(rootCmd, tmpdir, prepender, postpender, identity); err != nil {110- t.Fatalf("GenMarkdownTree failed: %v", err)111- }112-113- gotRoot := fileContents(t, tmpdir, "root.md")114- checkStringContains(t, gotRoot, "Prepended")115- checkStringContains(t, gotRoot, rootCmd.Long)116- checkStringContains(t, gotRoot, "Postpended")117-118- gotEcho := fileContents(t, tmpdir, "root_echo.md")119- checkStringContains(t, gotEcho, "Prepended")120- checkStringContains(t, gotEcho, echoCmd.Long)121- checkStringContains(t, gotEcho, "Postpended")122-123- gotEchoSub := fileContents(t, tmpdir, "root_echo_echosub.md")124- checkStringContains(t, gotEchoSub, "Prepended")125- checkStringContains(t, gotEchoSub, echoSubCmd.Long)126- checkStringContains(t, gotEchoSub, "Postpended")127-}128-98 func BenchmarkGenMarkdownToFile(b *testing.B) {99 file, err := ioutil.TempFile("", "")100 if err != nil {101 b.Fatal(err)7 unmodified lines109 b.Fatal(err)110 }111 }112 }144-145-func fileContents(t *testing.T, dir, filename string) string {146- contents, err := ioutil.ReadFile(filepath.Join(dir, filename))147- if err != nil {148- t.Fatalf("Error loading file %q: %v ", filename, err)149- }150- return string(contents)151-}modified:doc/md_docs.go+4 added-7 removed
120 unmodified lines121 // help output will be in the file `cmd-sub-third.1`.122 func GenMarkdownTree(cmd *cobra.Command, dir string) error {123 identity := func(s string) string { return s }124 emptyStr := func(s string) string { return "" }125- return GenMarkdownTreeCustom(cmd, dir, emptyStr, emptyStr, identity)125+ return GenMarkdownTreeCustom(cmd, dir, emptyStr, identity)126 }127 128 // GenMarkdownTreeCustom is the the same as GenMarkdownTree, but129-// with custom filePrepender, filePostpender, and linkHandler.130-func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, filePostpender, linkHandler func(string) string) error {129+// with custom filePrepender and linkHandler.130+func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {131 for _, c := range cmd.Commands() {132 if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {133 continue134 }135- if err := GenMarkdownTreeCustom(c, dir, filePrepender, filePostpender, linkHandler); err != nil {135+ if err := GenMarkdownTreeCustom(c, dir, filePrepender, linkHandler); err != nil {136 return err137 }138 }139 10 unmodified lines150 }151 if err := GenMarkdownCustom(cmd, f, linkHandler); err != nil {152 return err153 }154- if _, err := io.WriteString(f, filePostpender(filename)); err != nil {155- return err156- }154 return nil155 }