From eacb3de75920cf41a92f468dbeeea2d09c6940ac Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 30 Aug 2017 12:48:54 -0400 Subject: [PATCH] More arbitrary function for wrapping at a length --- command/base.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/command/base.go b/command/base.go index eda516fe45..7c4c2e92d8 100644 --- a/command/base.go +++ b/command/base.go @@ -1,11 +1,11 @@ package command import ( - "bufio" "bytes" "flag" "fmt" "io" + "io/ioutil" "regexp" "strings" "sync" @@ -287,13 +287,13 @@ func printFlagDetail(w io.Writer, f *flag.Flag) { } usage := reRemoveWhitespace.ReplaceAllString(f.Usage, " ") - indented := wrapAtLength(usage, 6) + indented := wrapAtLengthWithPadding(usage, 6) fmt.Fprintf(w, "%s\n\n", indented) } -// wrapAtLength wraps the given text at the maxLineLength, taking into account -// any provided left padding. -func wrapAtLength(s string, pad int) string { +// wrapAtLengthWithPadding wraps the given text at the maxLineLength, taking +// into account any provided left padding. +func wrapAtLengthWithPadding(s string, pad int) string { wrapped := text.Wrap(s, maxLineLength-pad) lines := strings.Split(wrapped, "\n") for i, line := range lines { @@ -302,6 +302,11 @@ func wrapAtLength(s string, pad int) string { return strings.Join(lines, "\n") } +// wrapAtLength wraps the given text to maxLineLength. +func wrapAtLength(s string) string { + return wrapAtLengthWithPadding(s, 0) +} + // FlagSets is a group of flag sets. type FlagSets struct { flagSets []*FlagSet