Skip to content

Commit

Permalink
feat: add support for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jon4hz authored and muesli committed Sep 8, 2022
1 parent b18accb commit 5040723
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions mango.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Command struct {
Name string
Short string
Usage string
Example string
Flags map[string]Flag
Commands map[string]*Command
}
Expand Down Expand Up @@ -176,6 +177,24 @@ func (m ManPage) buildCommand(w Builder, c Command) {
w.IndentEnd()
}
}

if c.Example != "" {
if c.Name == m.Root.Name {
w.Section("Examples")
w.TaggedParagraph(-1)
} else {
w.TaggedParagraph(-1)
w.TextBold("EXAMPLES")
w.Indent(4)
}
w.Text(c.Example)

if c.Name == m.Root.Name {
w.EndSection()
} else {
w.IndentEnd()
}
}
}

// Build generates the man page.
Expand Down

0 comments on commit 5040723

Please sign in to comment.