Skip to content

Commit

Permalink
(misc) Handle deprecated methods
Browse files Browse the repository at this point in the history
Signed-off-by: R.I.Pienaar <[email protected]>
  • Loading branch information
ripienaar committed Dec 19, 2023
1 parent a5b8657 commit edda7b9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"fmt"
"go/doc"
"go/doc/comment"
"io"
"strings"
"text/template"
Expand Down Expand Up @@ -33,7 +34,14 @@ func formatTwoColumns(w io.Writer, indent, padding, width int, rows [][2]string)

for _, row := range rows {
buf := bytes.NewBuffer(nil)
doc.ToText(buf, row[1], "", preIndent, width-s-padding-indent)
d := new(doc.Package).Parser().Parse(row[1])
pr := &comment.Printer{
TextPrefix: "",
TextCodePrefix: preIndent,
TextWidth: width - s - padding - indent,
}
buf.Write(pr.Text(d))

lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
fmt.Fprintf(w, "%s%-*s%*s", indentStr, s, row[0], padding, "")
if len(row[0]) >= max {
Expand Down Expand Up @@ -134,7 +142,15 @@ func (a *Application) UsageForContextWithTemplate(context *ParseContext, indent
"Wrap": func(indent int, s string) string {
buf := bytes.NewBuffer(nil)
indentText := strings.Repeat(" ", indent)
doc.ToText(buf, s, indentText, " "+indentText, width-indent)

d := new(doc.Package).Parser().Parse(s)
pr := &comment.Printer{
TextPrefix: indentText,
TextCodePrefix: " " + indentText,
TextWidth: width - indent,
}
buf.Write(pr.Text(d))

return buf.String()
},
"FormatFlag": formatFlag,
Expand Down

0 comments on commit edda7b9

Please sign in to comment.