Skip to content

Commit

Permalink
Ensure SEE ALSO list has no leading comma, fixing spf13#229
Browse files Browse the repository at this point in the history
  • Loading branch information
garthk committed Jan 21, 2016
1 parent 8e91712 commit cb8496d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions doc/man_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
}
if hasSeeAlso(cmd) {
fmt.Fprintf(buf, "# SEE ALSO\n")
seealsos := make([]string, 0)
if cmd.HasParent() {
parentPath := cmd.Parent().CommandPath()
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
fmt.Fprintf(buf, "**%s(%s)**", dashParentPath, header.Section)
seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
seealsos = append(seealsos, seealso)
cmd.VisitParents(func(c *cobra.Command) {
if c.DisableAutoGenTag {
cmd.DisableAutoGenTag = c.DisableAutoGenTag
Expand All @@ -200,16 +202,14 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
}
children := cmd.Commands()
sort.Sort(byName(children))
for i, c := range children {
for _, c := range children {
if !c.IsAvailableCommand() || c.IsHelpCommand() {
continue
}
if cmd.HasParent() || i > 0 {
fmt.Fprintf(buf, ", ")
}
fmt.Fprintf(buf, "**%s-%s(%s)**", dashCommandName, c.Name(), header.Section)
seealso := fmt.Sprintf("**%s-%s(%s)**", dashCommandName, c.Name(), header.Section)
seealsos = append(seealsos, seealso)
}
fmt.Fprintf(buf, "\n")
fmt.Fprintf(buf, "%s\n", strings.Join(seealsos, ", "))
}
if !cmd.DisableAutoGenTag {
fmt.Fprintf(buf, "# HISTORY\n%s Auto generated by spf13/cobra\n", header.Date.Format("2-Jan-2006"))
Expand Down

0 comments on commit cb8496d

Please sign in to comment.