Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
proposal: x/tools/cmd/godoc: add -exclude_gopath #25364
It would be helpful to add an "-exclude_gopath" flag to godoc command.
Godoc automatically includes the default Go path value without any apparent option to disable this behaviour. It could be helpful in certain cases to disable this behaviour, for example, when a user wishes just to exam only the official Go standard library documentation and not EVERYTHING they currently have in their source folder. This would be helpful when a user is trying to learn Go by reading the official documentation in an offline mode by using "godoc -http". The current behaviour makes readability quite poor if the user has a large number of packages installed and is primarily interested in only the official documentation.
Currently, the user's $GOPATH environment variable can't even be used to temporarily override this default behaviour, for example:
This example command line fails because build.Default.GOPATH adds Go's default GOPATH value regardless.
Rather than suggest a change to the build context default, I'm proposing that a flag be added to the godoc cmd that enables a user to simply exclude the GOPATH source files from a godoc command session.
The following lines would be added to / changed in main.go:
This proposal avoids any platform specific issues by simply entirely bypassing the processing of that path. If any future changes were to the underling default context to better support this behaviour it could easily be rolled back.
If this proposed change is accepted then I'd naturally be happy to write it up.
Yes, only if your GOPATH is the default one, which is "/home/user/go". Hence when you set the env var to "", it falls back to that. Just set the env var to some dummy value like -
Also, note that the next version of godoc will group packages in the standard library and the GOPATH into separate collapsible sections. So they will be much more manageable, since I see that readability was also one of your concerns.
I am going to close this has been raised in the past and a reasonable alternative already exists. And godoc already has better segregation of user source libraries and the standard library in the next release.
Please comment if you disagree.