From 50407234dce52e233c96b748504890cf11d2706d Mon Sep 17 00:00:00 2001 From: jon4hz Date: Tue, 30 Aug 2022 12:29:56 +0200 Subject: [PATCH] feat: add support for examples --- mango.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mango.go b/mango.go index e7b6dd7..a7f00d0 100644 --- a/mango.go +++ b/mango.go @@ -22,6 +22,7 @@ type Command struct { Name string Short string Usage string + Example string Flags map[string]Flag Commands map[string]*Command } @@ -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.