(cmd *cobra.Command, header *GenManHeader)
| 200 | } |
| 201 | |
| 202 | func genMan(cmd *cobra.Command, header *GenManHeader) []byte { |
| 203 | cmd.InitDefaultHelpCmd() |
| 204 | cmd.InitDefaultHelpFlag() |
| 205 | |
| 206 | // something like `rootcmd-subcmd1-subcmd2` |
| 207 | dashCommandName := strings.ReplaceAll(cmd.CommandPath(), " ", "-") |
| 208 | |
| 209 | buf := new(bytes.Buffer) |
| 210 | |
| 211 | manPreamble(buf, header, cmd, dashCommandName) |
| 212 | manPrintOptions(buf, cmd) |
| 213 | if len(cmd.Example) > 0 { |
| 214 | buf.WriteString("# EXAMPLE\n") |
| 215 | fmt.Fprintf(buf, "```\n%s\n```\n", cmd.Example) |
| 216 | } |
| 217 | if hasSeeAlso(cmd) { |
| 218 | buf.WriteString("# SEE ALSO\n") |
| 219 | seealsos := make([]string, 0) |
| 220 | if cmd.HasParent() { |
| 221 | parentPath := cmd.Parent().CommandPath() |
| 222 | dashParentPath := strings.ReplaceAll(parentPath, " ", "-") |
| 223 | seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section) |
| 224 | seealsos = append(seealsos, seealso) |
| 225 | cmd.VisitParents(func(c *cobra.Command) { |
| 226 | if c.DisableAutoGenTag { |
| 227 | cmd.DisableAutoGenTag = c.DisableAutoGenTag |
| 228 | } |
| 229 | }) |
| 230 | } |
| 231 | children := cmd.Commands() |
| 232 | sort.Sort(byName(children)) |
| 233 | for _, c := range children { |
| 234 | if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() { |
| 235 | continue |
| 236 | } |
| 237 | seealso := fmt.Sprintf("**%s-%s(%s)**", dashCommandName, c.Name(), header.Section) |
| 238 | seealsos = append(seealsos, seealso) |
| 239 | } |
| 240 | buf.WriteString(strings.Join(seealsos, ", ") + "\n") |
| 241 | } |
| 242 | if !cmd.DisableAutoGenTag { |
| 243 | fmt.Fprintf(buf, "# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006")) |
| 244 | } |
| 245 | return buf.Bytes() |
| 246 | } |
no test coverage detected