More arbitrary function for wrapping at a length
This commit is contained in:
parent
9347c110f2
commit
5093b8dff8
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue