cmd/doc: add -all flag to print all documentation for package

Unlike the one for the old godoc, you need the -u flag to see
unexported symbols. This seems like the right behavior: it's
consistent.

For now at least, the argument must be a package, not a symbol.
This is also different from old godoc.

Required a little refactoring but also cleaned up a few things.

Update #25595

Leaving the bug open for now until we tackle
	go doc -all symbol

Change-Id: Ibc1975bfa592cb1e92513eb2e5e9e11e01a60095
Reviewed-on: https://go-review.googlesource.com/c/141977
Run-TryBot: Rob Pike <r@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Rob Pike 2018-10-13 21:06:43 +11:00
parent ee76992200
commit 101a677ebf
5 changed files with 327 additions and 92 deletions

View file

@ -147,6 +147,69 @@ var tests = []test{
`type T1 T2`, // Type alias does not display as type declaration.
},
},
// Package dump -all
{
"full package",
[]string{"-all", p},
[]string{
`package pkg .*import`,
`Package comment`,
`CONSTANTS`,
`Comment before ConstOne`,
`ConstOne = 1`,
`ConstTwo = 2 // Comment on line with ConstTwo`,
`ConstFive`,
`ConstSix`,
`Const block where first entry is unexported`,
`ConstLeft2, constRight2 uint64`,
`constLeft3, ConstRight3`,
`ConstLeft4, ConstRight4`,
`Duplicate = iota`,
`const CaseMatch = 1`,
`const Casematch = 2`,
`const ExportedConstant = 1`,
`const MultiLineConst = `,
`MultiLineString1`,
`VARIABLES`,
`Comment before VarOne`,
`VarOne = 1`,
`Comment about block of variables`,
`VarFive = 5`,
`var ExportedVariable = 1`,
`var LongLine = newLongLine\(`,
`var MultiLineVar = map\[struct {`,
`FUNCTIONS`,
`func ExportedFunc\(a int\) bool`,
`Comment about exported function`,
`func MultiLineFunc\(x interface`,
`func ReturnUnexported\(\) unexportedType`,
`TYPES`,
`type ExportedInterface interface`,
`type ExportedStructOneField struct`,
`type ExportedType struct`,
`Comment about exported type`,
`const ConstGroup4 ExportedType = ExportedType`,
`ExportedTypedConstant ExportedType = iota`,
`Constants tied to ExportedType`,
`func ExportedTypeConstructor\(\) \*ExportedType`,
`Comment about constructor for exported type`,
`func ReturnExported\(\) ExportedType`,
`func \(ExportedType\) ExportedMethod\(a int\) bool`,
`Comment about exported method`,
`type T1 = T2`,
`type T2 int`,
},
[]string{
`constThree`,
`_, _ uint64 = 2 \* iota, 1 << iota`,
`constLeft1, constRight1`,
`duplicate`,
`varFour`,
`func internalFunc`,
`unexportedField`,
`func \(unexportedType\)`,
},
},
// Package dump -u
{
"full package with u",
@ -164,6 +227,58 @@ var tests = []test{
`MultiLine(String|Method|Field)`, // No data from multi line portions.
},
},
// Package dump -u -all
{
"full package",
[]string{"-u", "-all", p},
[]string{
`package pkg .*import`,
`Package comment`,
`CONSTANTS`,
`Comment before ConstOne`,
`ConstOne += 1`,
`ConstTwo += 2 // Comment on line with ConstTwo`,
`constThree = 3 // Comment on line with constThree`,
`ConstFive`,
`const internalConstant += 2`,
`Comment about internal constant`,
`VARIABLES`,
`Comment before VarOne`,
`VarOne += 1`,
`Comment about block of variables`,
`varFour += 4`,
`VarFive += 5`,
`varSix += 6`,
`var ExportedVariable = 1`,
`var LongLine = newLongLine\(`,
`var MultiLineVar = map\[struct {`,
`var internalVariable = 2`,
`Comment about internal variable`,
`FUNCTIONS`,
`func ExportedFunc\(a int\) bool`,
`Comment about exported function`,
`func MultiLineFunc\(x interface`,
`func internalFunc\(a int\) bool`,
`Comment about internal function`,
`func newLongLine\(ss .*string\)`,
`TYPES`,
`type ExportedType struct`,
`type T1 = T2`,
`type T2 int`,
`type unexportedType int`,
`Comment about unexported type`,
`ConstGroup1 unexportedType = iota`,
`ConstGroup2`,
`ConstGroup3`,
`ExportedTypedConstant_unexported unexportedType = iota`,
`Constants tied to unexportedType`,
`const unexportedTypedConstant unexportedType = 1`,
`func ReturnUnexported\(\) unexportedType`,
`func \(unexportedType\) ExportedMethod\(\) bool`,
`func \(unexportedType\) unexportedMethod\(\) bool`,
},
nil,
},
// Single constant.
{
@ -361,7 +476,6 @@ var tests = []test{
`io.Reader.*Comment on line with embedded Reader`,
},
[]string{
`int.*embedded`, // No unexported embedded field.
`Comment about exported method`, // No comment about exported method.
`unexportedMethod`, // No unexported method.
`unexportedTypedConstant`, // No unexported constant.