GenReSTCustom creates custom reStructured Text output.
(cmd *cobra.Command, w io.Writer, linkHandler func(string, string) string)
| 60 | |
| 61 | // GenReSTCustom creates custom reStructured Text output. |
| 62 | func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, string) string) error { |
| 63 | cmd.InitDefaultHelpCmd() |
| 64 | cmd.InitDefaultHelpFlag() |
| 65 | |
| 66 | buf := new(bytes.Buffer) |
| 67 | name := cmd.CommandPath() |
| 68 | |
| 69 | short := cmd.Short |
| 70 | long := cmd.Long |
| 71 | if len(long) == 0 { |
| 72 | long = short |
| 73 | } |
| 74 | ref := strings.ReplaceAll(name, " ", "_") |
| 75 | |
| 76 | buf.WriteString(".. _" + ref + ":\n\n") |
| 77 | buf.WriteString(name + "\n") |
| 78 | buf.WriteString(strings.Repeat("-", len(name)) + "\n\n") |
| 79 | buf.WriteString(short + "\n\n") |
| 80 | buf.WriteString("Synopsis\n") |
| 81 | buf.WriteString("~~~~~~~~\n\n") |
| 82 | buf.WriteString("\n" + long + "\n\n") |
| 83 | |
| 84 | if cmd.Runnable() { |
| 85 | fmt.Fprintf(buf, "::\n\n %s\n\n", cmd.UseLine()) |
| 86 | } |
| 87 | |
| 88 | if len(cmd.Example) > 0 { |
| 89 | buf.WriteString("Examples\n") |
| 90 | buf.WriteString("~~~~~~~~\n\n") |
| 91 | fmt.Fprintf(buf, "::\n\n%s\n\n", indentString(cmd.Example, " ")) |
| 92 | } |
| 93 | |
| 94 | if err := printOptionsReST(buf, cmd, name); err != nil { |
| 95 | return err |
| 96 | } |
| 97 | if hasSeeAlso(cmd) { |
| 98 | buf.WriteString("SEE ALSO\n") |
| 99 | buf.WriteString("~~~~~~~~\n\n") |
| 100 | if cmd.HasParent() { |
| 101 | parent := cmd.Parent() |
| 102 | pname := parent.CommandPath() |
| 103 | ref = strings.ReplaceAll(pname, " ", "_") |
| 104 | fmt.Fprintf(buf, "* %s \t - %s\n", linkHandler(pname, ref), parent.Short) |
| 105 | cmd.VisitParents(func(c *cobra.Command) { |
| 106 | if c.DisableAutoGenTag { |
| 107 | cmd.DisableAutoGenTag = c.DisableAutoGenTag |
| 108 | } |
| 109 | }) |
| 110 | } |
| 111 | |
| 112 | children := cmd.Commands() |
| 113 | sort.Sort(byName(children)) |
| 114 | |
| 115 | for _, child := range children { |
| 116 | if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() { |
| 117 | continue |
| 118 | } |
| 119 | cname := name + " " + child.Name() |
no test coverage detected