diff --git a/src/cmd/doc/main.go b/src/cmd/doc/main.go index dda6aec22cd..0985d95b60a 100644 --- a/src/cmd/doc/main.go +++ b/src/cmd/doc/main.go @@ -11,10 +11,12 @@ // One argument: // go doc // go doc [.] -// go doc [].[.] +// go doc [.][.] +// go doc [.][.] // The first item in this list that succeeds is the one whose documentation // is printed. If there is a symbol but no package, the package in the current -// directory is chosen. +// directory is chosen. However, if the argument begins with a capital +// letter it is always assumed to be a symbol in the current directory. // // Two arguments: // go doc [.] diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 941d4714095..d11a5a00f79 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -225,12 +225,15 @@ which is schematically one of these: go doc go doc [.] - go doc [].[.] + go doc [.][.] + go doc [.][.] -The first item in this list matched by the argument is the one whose -documentation is printed. (See the examples below.) For packages, the order of -scanning is determined lexically, but the GOROOT tree is always scanned before -GOPATH. +The first item in this list matched by the argument is the one whose documentation +is printed. (See the examples below.) However, if the argument starts with a capital +letter it is assumed to identify a symbol or method in the current directory. + +For packages, the order of scanning is determined lexically, but the GOROOT tree +is always scanned before GOPATH. If there is no package specified or matched, the package in the current directory is selected, so "go doc Foo" shows the documentation for symbol Foo in @@ -278,6 +281,14 @@ Examples: go doc text/template new # Two arguments Show documentation for text/template's New function. + At least in the current tree, these invocations all print the + documentation for json.Decoder's Decode method: + + go doc json.Decoder.Decode + go doc json.decoder.decode + go doc json.decode + cd go/src/encoding/json; go doc decode + Flags: -c Respect case when matching symbols. diff --git a/src/cmd/go/doc.go b/src/cmd/go/doc.go index 4a07dfe11f4..bed763679d2 100644 --- a/src/cmd/go/doc.go +++ b/src/cmd/go/doc.go @@ -32,12 +32,15 @@ which is schematically one of these: go doc go doc [.] - go doc [].[.] + go doc [.][.] + go doc [.][.] -The first item in this list matched by the argument is the one whose -documentation is printed. (See the examples below.) For packages, the order of -scanning is determined lexically, but the GOROOT tree is always scanned before -GOPATH. +The first item in this list matched by the argument is the one whose documentation +is printed. (See the examples below.) However, if the argument starts with a capital +letter it is assumed to identify a symbol or method in the current directory. + +For packages, the order of scanning is determined lexically, but the GOROOT tree +is always scanned before GOPATH. If there is no package specified or matched, the package in the current directory is selected, so "go doc Foo" shows the documentation for symbol Foo in @@ -85,6 +88,14 @@ Examples: go doc text/template new # Two arguments Show documentation for text/template's New function. + At least in the current tree, these invocations all print the + documentation for json.Decoder's Decode method: + + go doc json.Decoder.Decode + go doc json.decoder.decode + go doc json.decode + cd go/src/encoding/json; go doc decode + Flags: -c Respect case when matching symbols.