re-assemble the doc string the easy way

This commit is contained in:
Josh Humphries 2018-10-18 12:49:54 -04:00
parent 9ad6a72e7b
commit f9befe0bde
1 changed files with 12 additions and 21 deletions

View File

@ -529,29 +529,20 @@ Available flags:
} }
func prettify(docString string) string { func prettify(docString string) string {
var buf bytes.Buffer parts := strings.Split(docString, "\n")
first := true
for { // cull empty lines and also remove trailing and leading spaces
pos := strings.IndexByte(docString, '\n') // from each line in the doc string
if pos < 0 { j := 0
pos = len(docString) for _, part := range parts {
if part == "" {
continue
} }
line := strings.TrimSpace(docString[:pos]) parts[j] = strings.TrimSpace(part)
if line != "" { j++
if first {
first = false
} else {
buf.WriteByte('\n')
buf.WriteString(indent())
}
buf.WriteString(line)
}
if pos >= len(docString) {
break
}
docString = docString[pos+1:]
} }
return buf.String()
return strings.Join(parts[:j], "\n"+indent())
} }
func warn(msg string, args ...interface{}) { func warn(msg string, args ...interface{}) {