From fa42157d986c69664e2146b520ff45be204af8eb Mon Sep 17 00:00:00 2001 From: Gert Cuykens Date: Thu, 27 Jun 2019 03:04:21 +0200 Subject: cmd/doc: add option to output a clean one-line symbol representation Currently there is no way for go doc to output a clean one-line symbol representation of types, functions, vars and consts without documentation lines or other text lines added. For example `go doc fmt` has a huge introduction so if you pass that to grep or fzf to search a symbol let say scan `go doc fmt | grep scan` you get way to many false positives. Added a `-short` flag to be able to do `go doc -short fmt | grep scan` instead which will result in just the symbols you are looking for. func Fscan(r io.Reader, a ...interface{}) (n int, err error) func Fscanf(r io.Reader, format string, a ...interface{}) (n int, err error) func Fscanln(r io.Reader, a ...interface{}) (n int, err error) func Sscan(str string, a ...interface{}) (n int, err error) func Sscanf(str string, format string, a ...interface{}) (n int, err error) func Sscanln(str string, a ...interface{}) (n int, err error) Fixes #32597 Change-Id: I77a73838adc512c8d1490f5a82075de6b0462a31 Reviewed-on: https://go-review.googlesource.com/c/go/+/184017 Run-TryBot: Andrew Bonventre TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- src/cmd/doc/pkg.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/cmd/doc/pkg.go') diff --git a/src/cmd/doc/pkg.go b/src/cmd/doc/pkg.go index 2c0c6c161a..fa31eba64b 100644 --- a/src/cmd/doc/pkg.go +++ b/src/cmd/doc/pkg.go @@ -507,24 +507,34 @@ func (pkg *Package) allDoc() { func (pkg *Package) packageDoc() { defer pkg.flush() - doc.ToText(&pkg.buf, pkg.doc.Doc, "", indent, indentedWidth) - pkg.newlines(1) + if !short { + doc.ToText(&pkg.buf, pkg.doc.Doc, "", indent, indentedWidth) + pkg.newlines(1) + } if pkg.pkg.Name == "main" && !showCmd { // Show only package docs for commands. return } - pkg.newlines(2) // Guarantee blank line before the components. + if !short { + pkg.newlines(2) // Guarantee blank line before the components. + } + pkg.valueSummary(pkg.doc.Consts, false) pkg.valueSummary(pkg.doc.Vars, false) pkg.funcSummary(pkg.doc.Funcs, false) pkg.typeSummary() - pkg.bugs() + if !short { + pkg.bugs() + } } // packageClause prints the package clause. func (pkg *Package) packageClause() { + if short { + return + } importPath := pkg.build.ImportComment if importPath == "" { importPath = pkg.build.ImportPath -- cgit v1.3-5-g45d5