More arbitrary function for wrapping at a length

This commit is contained in:
Seth Vargo 2017-08-30 12:48:54 -04:00
parent 9347c110f2
commit 5093b8dff8
No known key found for this signature in database
GPG Key ID: C921994F9C27E0FF
1 changed files with 10 additions and 5 deletions

View File

@ -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