]> Cypherpunks repositories - gostls13.git/commitdiff
go/doc: use regexp for -notes instead of comma-sep. list
authorRobert Griesemer <gri@golang.org>
Thu, 21 Mar 2013 22:56:15 +0000 (15:56 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 21 Mar 2013 22:56:15 +0000 (15:56 -0700)
-notes="BUG|TODO" instead of -notes="BUG,TODO".
Permits -notes=".*" to see all notes.

R=cnicolaou
CC=golang-dev
https://golang.org/cl/7951043

src/cmd/godoc/doc.go
src/cmd/godoc/godoc.go

index ddb6d2687256137935dedee97ce24e4f552aa9fa..e5f5324cd47c9812f19086b37494f3a391e872fc 100644 (file)
@@ -67,6 +67,9 @@ The flags are:
        -maxresults=10000
                maximum number of full text search results shown
                (no full text index is built if maxresults <= 0)
+       -notes="BUG"
+               regular expression matching note markers to show
+               (e.g., "BUG|TODO", ".*")
        -html
                print HTML in command-line mode
        -goroot=$GOROOT
index 82ede0d14e21c879dfcae294572beee0b2fa5400..57743211300abadfd775ecc3ecd54cf2d47328a5 100644 (file)
@@ -84,15 +84,11 @@ var (
        cmdHandler docServer
        pkgHandler docServer
 
-       // which code 'Notes' to show
-       notes = flag.String("notes", "BUG", "comma separated list of Note markers as per pkg:go/doc")
-       // list of 'Notes' to show
-       notesToShow []string
+       // source code notes
+       notes = flag.String("notes", "BUG", "regular expression matching note markers to show")
 )
 
 func initHandlers() {
-       notesToShow = strings.Split(*notes, ",")
-
        fileServer = http.FileServer(&httpFS{fs})
        cmdHandler = docServer{"/cmd/", "/src/cmd"}
        pkgHandler = docServer{"/pkg/", "/src/pkg"}
@@ -1100,10 +1096,15 @@ func (h *docServer) getPageInfo(abspath, relpath string, mode PageInfoMode) (inf
 
                        // collect any notes that we want to show
                        if info.PDoc.Notes != nil {
-                               info.Notes = make(map[string][]*doc.Note)
-                               for _, m := range notesToShow {
-                                       if n := info.PDoc.Notes[m]; n != nil {
-                                               info.Notes[m] = n
+                               // could regexp.Compile only once per godoc, but probably not worth it
+                               if rx, err := regexp.Compile(*notes); err == nil {
+                                       for m, n := range info.PDoc.Notes {
+                                               if rx.MatchString(m) {
+                                                       if info.Notes == nil {
+                                                               info.Notes = make(map[string][]*doc.Note)
+                                                       }
+                                                       info.Notes[m] = n
+                                               }
                                        }
                                }
                        }