]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: don't hide package lookup error if there's no command with the same name
authorRobert Griesemer <gri@golang.org>
Tue, 15 Feb 2011 01:41:47 +0000 (17:41 -0800)
committerRobert Griesemer <gri@golang.org>
Tue, 15 Feb 2011 01:41:47 +0000 (17:41 -0800)
Fixes #1514.

R=r, r2
CC=golang-dev
https://golang.org/cl/4173050

src/cmd/godoc/godoc.go
src/cmd/godoc/main.go

index 86d1719805305e3da6f72301235009c8f5a58dee..c91dc33dbbc36e747f973b95300bca9f61cdde11 100644 (file)
@@ -896,6 +896,11 @@ type PageInfo struct {
 }
 
 
+func (info *PageInfo) IsEmpty() bool {
+       return info.Err != nil || info.PAst == nil && info.PDoc == nil && info.Dirs == nil
+}
+
+
 type httpHandler struct {
        pattern string // url pattern; e.g. "/pkg/"
        fsRoot  string // file system root to which the pattern is mapped
index 145eeac346d7eaa9bae4faf954d47498e16798d4..ea1e3c42e13d3998c6580f47da053d2d767db78b 100644 (file)
@@ -217,6 +217,7 @@ func makeRx(names []string) (rx *regexp.Regexp) {
        return
 }
 
+
 func main() {
        flag.Usage = usage
        flag.Parse()
@@ -336,12 +337,17 @@ func main() {
        //            if there are multiple packages in a directory.
        info := pkgHandler.getPageInfo(abspath, relpath, "", mode)
 
-       if info.Err != nil || info.PAst == nil && info.PDoc == nil && info.Dirs == nil {
+       if info.IsEmpty() {
                // try again, this time assume it's a command
                if !pathutil.IsAbs(path) {
                        abspath = absolutePath(path, cmdHandler.fsRoot)
                }
-               info = cmdHandler.getPageInfo(abspath, relpath, "", mode)
+               cmdInfo := cmdHandler.getPageInfo(abspath, relpath, "", mode)
+               // only use the cmdInfo if it actually contains a result
+               // (don't hide errors reported from looking up a package)
+               if !cmdInfo.IsEmpty() {
+                       info = cmdInfo
+               }
        }
        if info.Err != nil {
                log.Fatalf("%v", info.Err)