aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2011-02-14 17:41:47 -0800
committerRobert Griesemer <gri@golang.org>2011-02-14 17:41:47 -0800
commite6ee0d24924f926f3a648fdcd5e5ccb81e1d4f14 (patch)
tree76920a1366f8540de1795f2f7c3dc6d6578f5764
parent34dd450fb88f8ee1750f9601a20b83b48ac87da8 (diff)
downloadgo-e6ee0d24924f926f3a648fdcd5e5ccb81e1d4f14.tar.gz
go-e6ee0d24924f926f3a648fdcd5e5ccb81e1d4f14.zip
godoc: don't hide package lookup error if there's no command with the same name
Fixes #1514. R=r, r2 CC=golang-dev https://golang.org/cl/4173050
-rw-r--r--src/cmd/godoc/godoc.go5
-rw-r--r--src/cmd/godoc/main.go10
2 files changed, 13 insertions, 2 deletions
diff --git a/src/cmd/godoc/godoc.go b/src/cmd/godoc/godoc.go
index 86d1719805..c91dc33dbb 100644
--- a/src/cmd/godoc/godoc.go
+++ b/src/cmd/godoc/godoc.go
@@ -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
diff --git a/src/cmd/godoc/main.go b/src/cmd/godoc/main.go
index 145eeac346..ea1e3c42e1 100644
--- a/src/cmd/godoc/main.go
+++ b/src/cmd/godoc/main.go
@@ -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)