genMarkdownCustom creates custom markdown output.
(cmd *cobra.Command, w io.Writer, linkHandler func(string) string)
| 131 | |
| 132 | // genMarkdownCustom creates custom markdown output. |
| 133 | func genMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) string) error { |
| 134 | fmt.Fprint(w, "{% raw %}") |
| 135 | fmt.Fprintf(w, "## %s\n\n", cmd.CommandPath()) |
| 136 | |
| 137 | hasLong := cmd.Long != "" |
| 138 | if !hasLong { |
| 139 | fmt.Fprintf(w, "%s\n\n", cmd.Short) |
| 140 | } |
| 141 | if cmd.Runnable() { |
| 142 | fmt.Fprintf(w, "```\n%s\n```\n\n", cmd.UseLine()) |
| 143 | } |
| 144 | if hasLong { |
| 145 | fmt.Fprintf(w, "%s\n\n", cmd.Long) |
| 146 | } |
| 147 | |
| 148 | for _, g := range root.GroupedCommands(cmd) { |
| 149 | fmt.Fprintf(w, "### %s\n\n", g.Title) |
| 150 | for _, subcmd := range g.Commands { |
| 151 | fmt.Fprintf(w, "* [%s](%s)\n", subcmd.CommandPath(), linkHandler(cmdManualPath(subcmd))) |
| 152 | } |
| 153 | fmt.Fprint(w, "\n\n") |
| 154 | } |
| 155 | |
| 156 | if err := printOptions(w, cmd); err != nil { |
| 157 | return err |
| 158 | } |
| 159 | printAliases(w, cmd) |
| 160 | printJSONFields(w, cmd) |
| 161 | fmt.Fprint(w, "{% endraw %}\n") |
| 162 | |
| 163 | if len(cmd.Example) > 0 { |
| 164 | fmt.Fprint(w, "### Examples\n\n{% highlight bash %}{% raw %}\n") |
| 165 | fmt.Fprint(w, cmd.Example) |
| 166 | fmt.Fprint(w, "{% endraw %}{% endhighlight %}\n\n") |
| 167 | } |
| 168 | |
| 169 | if cmd.HasParent() { |
| 170 | p := cmd.Parent() |
| 171 | fmt.Fprint(w, "### See also\n\n") |
| 172 | fmt.Fprintf(w, "* [%s](%s)\n", p.CommandPath(), linkHandler(cmdManualPath(p))) |
| 173 | } |
| 174 | |
| 175 | return nil |
| 176 | } |
| 177 | |
| 178 | // GenMarkdownTreeCustom is the same as GenMarkdownTree, but |
| 179 | // with custom filePrepender and linkHandler. |