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:
parent
c4b4e4b0fa
commit
39919aea04
|
@ -72,6 +72,7 @@ var (
|
||||||
// layout control
|
// layout control
|
||||||
html = flag.Bool("html", false, "print HTML in command-line mode")
|
html = flag.Bool("html", false, "print HTML in command-line mode")
|
||||||
srcMode = flag.Bool("src", false, "print (exported) source 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")
|
urlFlag = flag.String("url", "", "print HTML for named URL")
|
||||||
|
|
||||||
// command-line searches
|
// command-line searches
|
||||||
|
@ -253,6 +254,7 @@ func main() {
|
||||||
pres.DeclLinks = *declLinks
|
pres.DeclLinks = *declLinks
|
||||||
pres.SrcMode = *srcMode
|
pres.SrcMode = *srcMode
|
||||||
pres.HTMLMode = *html
|
pres.HTMLMode = *html
|
||||||
|
pres.AllMode = *allMode
|
||||||
if *notesRx != "" {
|
if *notesRx != "" {
|
||||||
pres.NotesRx = regexp.MustCompile(*notesRx)
|
pres.NotesRx = regexp.MustCompile(*notesRx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,9 @@ func CommandLine(w io.Writer, fs vfs.NameSpace, pres *Presentation, args []strin
|
||||||
// the fake built-in package contains unexported identifiers
|
// the fake built-in package contains unexported identifiers
|
||||||
mode = NoFiltering | NoTypeAssoc
|
mode = NoFiltering | NoTypeAssoc
|
||||||
}
|
}
|
||||||
|
if pres.AllMode {
|
||||||
|
mode |= NoFiltering
|
||||||
|
}
|
||||||
if srcMode {
|
if srcMode {
|
||||||
// only filter exports if we don't have explicit command-line filter arguments
|
// only filter exports if we don't have explicit command-line filter arguments
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
|
|
|
@ -172,6 +172,10 @@ func First() {
|
||||||
// Second function is second.
|
// Second function is second.
|
||||||
func Second() {
|
func Second() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unexported function is third.
|
||||||
|
func unexported() {
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
"src/gen/gen.go": `// Package gen
|
"src/gen/gen.go": `// Package gen
|
||||||
package gen
|
package gen
|
||||||
|
@ -220,6 +224,7 @@ package main
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
desc string
|
desc string
|
||||||
args []string
|
args []string
|
||||||
|
all bool
|
||||||
exp string
|
exp string
|
||||||
err bool
|
err bool
|
||||||
}{
|
}{
|
||||||
|
@ -253,6 +258,18 @@ package main
|
||||||
args: []string{"src/foo", "Second"},
|
args: []string{"src/foo", "Second"},
|
||||||
exp: "// Second function is second.\nfunc Second() {\n}",
|
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",
|
desc: "package w. //line comments",
|
||||||
args: []string{"gen", "F"},
|
args: []string{"gen", "F"},
|
||||||
|
@ -284,11 +301,12 @@ package main
|
||||||
exp: "",
|
exp: "",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
p.AllMode = tc.all
|
||||||
w := new(bytes.Buffer)
|
w := new(bytes.Buffer)
|
||||||
err := CommandLine(w, fs, p, tc.args)
|
err := CommandLine(w, fs, p, tc.args)
|
||||||
if got, want := w.String(), tc.exp; got != want || tc.err == (err == nil) {
|
if got, want := w.String(), tc.exp; got != want || tc.err == (err == nil) {
|
||||||
t.Errorf("%s: CommandLine(%v) = %q (%v); want %q (%v)",
|
t.Errorf("%s: CommandLine(%v), All(%v) = %q (%v); want %q (%v)",
|
||||||
tc.desc, tc.args, got, err, want, tc.err)
|
tc.desc, tc.args, tc.all, got, err, want, tc.err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ type Presentation struct {
|
||||||
SrcMode bool
|
SrcMode bool
|
||||||
// HTMLMode outputs HTML instead of plain text in command-line mode.
|
// HTMLMode outputs HTML instead of plain text in command-line mode.
|
||||||
HTMLMode bool
|
HTMLMode bool
|
||||||
|
// AllMode includes unexported identifiers in the output in command-line mode.
|
||||||
|
AllMode bool
|
||||||
|
|
||||||
// NotesRx optionally specifies a regexp to match
|
// NotesRx optionally specifies a regexp to match
|
||||||
// notes to render in the output.
|
// notes to render in the output.
|
||||||
|
|
Loading…
Reference in New Issue