re-assemble the doc string the easy way
This commit is contained in:
parent
9ad6a72e7b
commit
f9befe0bde
|
|
@ -529,29 +529,20 @@ Available flags:
|
|||
}
|
||||
|
||||
func prettify(docString string) string {
|
||||
var buf bytes.Buffer
|
||||
first := true
|
||||
for {
|
||||
pos := strings.IndexByte(docString, '\n')
|
||||
if pos < 0 {
|
||||
pos = len(docString)
|
||||
parts := strings.Split(docString, "\n")
|
||||
|
||||
// cull empty lines and also remove trailing and leading spaces
|
||||
// from each line in the doc string
|
||||
j := 0
|
||||
for _, part := range parts {
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
line := strings.TrimSpace(docString[:pos])
|
||||
if line != "" {
|
||||
if first {
|
||||
first = false
|
||||
} else {
|
||||
buf.WriteByte('\n')
|
||||
buf.WriteString(indent())
|
||||
parts[j] = strings.TrimSpace(part)
|
||||
j++
|
||||
}
|
||||
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{}) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue