]> Cypherpunks repositories - gostls13.git/commitdiff
godoc: fix path resolution for command-line one more time (sigh...)
authorRobert Griesemer <gri@golang.org>
Sat, 20 Feb 2010 00:23:19 +0000 (16:23 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 20 Feb 2010 00:23:19 +0000 (16:23 -0800)
R=rsc
CC=golang-dev
https://golang.org/cl/217058

src/cmd/godoc/main.go

index 5ce7f9d51b3511a472c7b7d742a18070c2d263e3..ded1d3607ad572ad65e4c3c2df9a29c58434d7e6 100644 (file)
@@ -33,6 +33,7 @@ import (
        "io"
        "log"
        "os"
+       pathutil "path"
        "time"
 )
 
@@ -224,11 +225,29 @@ func main() {
                packageText = packageHTML
        }
 
-       info := pkgHandler.getPageInfo(flag.Arg(0), flag.Arg(0), true)
+       // determine paths
+       path := flag.Arg(0)
+       if len(path) > 0 && path[0] == '.' {
+               // assume cwd; don't assume -goroot
+               cwd, _ := os.Getwd() // ignore errors
+               path = pathutil.Join(cwd, path)
+       }
+       relpath := path
+       abspath := path
+       if len(path) > 0 && path[0] != '/' {
+               abspath = absolutePath(path, pkgHandler.fsRoot)
+       } else {
+               relpath = relativePath(path)
+       }
+
+       info := pkgHandler.getPageInfo(abspath, relpath, true)
 
        if info.PDoc == nil && info.Dirs == nil {
                // try again, this time assume it's a command
-               info = cmdHandler.getPageInfo(flag.Arg(0), flag.Arg(0), false)
+               if len(path) > 0 && path[0] != '/' {
+                       abspath = absolutePath(path, cmdHandler.fsRoot)
+               }
+               info = cmdHandler.getPageInfo(abspath, relpath, false)
        }
 
        if info.PDoc != nil && flag.NArg() > 1 {