diff --git a/cmd/godoc/main.go b/cmd/godoc/main.go index 901e992a15..aa2996a440 100644 --- a/cmd/godoc/main.go +++ b/cmd/godoc/main.go @@ -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) } diff --git a/godoc/cmdline.go b/godoc/cmdline.go index 7c53681347..b531b4df75 100644 --- a/godoc/cmdline.go +++ b/godoc/cmdline.go @@ -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 { diff --git a/godoc/cmdline_test.go b/godoc/cmdline_test.go index 602f2bbaba..8c9ce22eec 100644 --- a/godoc/cmdline_test.go +++ b/godoc/cmdline_test.go @@ -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) } } } diff --git a/godoc/pres.go b/godoc/pres.go index 855117764e..b8205e24c1 100644 --- a/godoc/pres.go +++ b/godoc/pres.go @@ -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.