1
0
mirror of https://github.com/golang/go synced 2024-09-30 16:08:36 -06:00

cmd/godoc: provide -all flag to output unexported identifiers

This flag includes unexported identifiers in command-line mode.
It is equivalent to ?m=all in web mode.

Fixes golang/go#8093

Change-Id: I1e5a69626929d3430638d900f3e975b272a98c90
Reviewed-on: https://go-review.googlesource.com/99435
Run-TryBot: Andrew Bonventre <andybons@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Andrew Bonventre <andybons@golang.org>
This commit is contained in:
Yury Smolsky 2018-03-08 10:04:01 +02:00 committed by Andrew Bonventre
parent c4b4e4b0fa
commit 39919aea04
4 changed files with 27 additions and 2 deletions

View File

@ -72,6 +72,7 @@ var (
// layout control
html = flag.Bool("html", false, "print HTML in command-line mode")
srcMode = flag.Bool("src", false, "print (exported) source in command-line mode")
allMode = flag.Bool("all", false, "include unexported identifiers in command-line mode")
urlFlag = flag.String("url", "", "print HTML for named URL")
// command-line searches
@ -253,6 +254,7 @@ func main() {
pres.DeclLinks = *declLinks
pres.SrcMode = *srcMode
pres.HTMLMode = *html
pres.AllMode = *allMode
if *notesRx != "" {
pres.NotesRx = regexp.MustCompile(*notesRx)
}

View File

@ -48,6 +48,9 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin
// the fake built-in package contains unexported identifiers
mode = NoFiltering | NoTypeAssoc
}
if pres.AllMode {
mode |= NoFiltering
}
if srcMode {
// only filter exports if we don't have explicit command-line filter arguments
if len(args) > 1 {

View File

@ -172,6 +172,10 @@ func First() {
// Second function is second.
func Second() {
}
// unexported function is third.
func unexported() {
}
`,
"src/gen/gen.go": `// Package gen
package gen
@ -220,6 +224,7 @@ package main
for _, tc := range []struct {
desc string
args []string
all bool
exp string
err bool
}{
@ -253,6 +258,18 @@ package main
args: []string{"src/foo", "Second"},
exp: "// Second function is second.\nfunc Second() {\n}",
},
{
desc: "package w. unexported filter",
args: []string{"foo", "unexported"},
all: true,
exp: "PACKAGE \nfunc unexported()\n unexported function is third.\n",
},
{
desc: "package w. unexported filter",
args: []string{"foo", "unexported"},
all: false,
exp: "PACKAGE ",
},
{
desc: "package w. //line comments",
args: []string{"gen", "F"},
@ -284,11 +301,12 @@ package main
exp: "",
},
} {
p.AllMode = tc.all
w := new(bytes.Buffer)
err := CommandLine(w, fs, p, tc.args)
if got, want := w.String(), tc.exp; got != want || tc.err == (err == nil) {
t.Errorf("%s: CommandLine(%v) = %q (%v); want %q (%v)",
tc.desc, tc.args, got, err, want, tc.err)
t.Errorf("%s: CommandLine(%v), All(%v) = %q (%v); want %q (%v)",
tc.desc, tc.args, tc.all, got, err, want, tc.err)
}
}
}

View File

@ -53,6 +53,8 @@ type Presentation struct {
SrcMode bool
// HTMLMode outputs HTML instead of plain text in command-line mode.
HTMLMode bool
// AllMode includes unexported identifiers in the output in command-line mode.
AllMode bool
// NotesRx optionally specifies a regexp to match
// notes to render in the output.