From edda7b99a937ae59186011b3ea88ffc4bf4ef11a Mon Sep 17 00:00:00 2001 From: "R.I.Pienaar" Date: Tue, 19 Dec 2023 16:09:28 +0100 Subject: [PATCH] (misc) Handle deprecated methods Signed-off-by: R.I.Pienaar --- usage.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/usage.go b/usage.go index b0e1b3d..8e59c95 100644 --- a/usage.go +++ b/usage.go @@ -5,6 +5,7 @@ import ( "bytes" "fmt" "go/doc" + "go/doc/comment" "io" "strings" "text/template" @@ -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 { @@ -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,