From abbc2dfc2c431cfaa69580ab0f01d41c4d05d880 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Tue, 9 Feb 2021 15:23:05 +1100 Subject: [PATCH] More group formatting tweaks. --- help.go | 7 +++---- help_test.go | 9 +++------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/help.go b/help.go index 3cacad1..e107724 100644 --- a/help.go +++ b/help.go @@ -151,8 +151,7 @@ func printNodeDetail(w *helpWriter, node *Node, hide bool) { w.Wrap(group.Metadata.Title) } if group.Metadata.Description != "" { - w.Print("") - w.Wrap(group.Metadata.Description) + w.Indent().Wrap(group.Metadata.Description) w.Print("") } writeFlags(w.Indent(), group.Flags) @@ -173,8 +172,7 @@ func printNodeDetail(w *helpWriter, node *Node, hide bool) { w.Wrap(group.Metadata.Title) } if group.Metadata.Description != "" { - w.Print("") - w.Wrap(group.Metadata.Description) + w.Indent().Wrap(group.Metadata.Description) w.Print("") } @@ -348,6 +346,7 @@ func (h *helpWriter) Print(text string) { *h.lines = append(*h.lines, strings.TrimRight(h.indent+text, " ")) } +// Indent returns a new helpWriter indented by two characters. func (h *helpWriter) Indent() *helpWriter { return &helpWriter{indent: h.indent + " ", lines: h.lines, width: h.width - 2, HelpOptions: h.HelpOptions, helpFormatter: h.helpFormatter} } diff --git a/help_test.go b/help_test.go index 440ac34..ca0ab10 100644 --- a/help_test.go +++ b/help_test.go @@ -323,8 +323,7 @@ Flags: --free-bool A non grouped bool flag. Group title taken from the kong.ExplicitGroups option - -A group header + A group header --grouped-a-string=STRING A string flag grouped in A. --grouped-a-bool A bool flag grouped in A. @@ -337,8 +336,7 @@ Commands: A non grouped subcommand. Group title taken from the kong.ExplicitGroups option - -A group header + A group header one thing subcommand thing @@ -383,8 +381,7 @@ Flags: --a-free-string=STRING A non grouped string flag. Group title taken from the kong.ExplicitGroups option - -A group header + A group header --grouped-a-string=STRING A string flag grouped in A. --grouped-a-bool A bool flag grouped in A.