New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/godoc: No command name if package main is in "src" #22878
Comments
By 'src', do you mean $GOPATH/src'? |
Yes, sorry. I added that. |
Well, then it works as intended. The import path of a package may not be empty. |
I'm not sure I understand:
Maybe I'm missing something? |
All packages inside Also, note that the
I don't recall such an explicit piece of the docs, but it's very rare for people to put code there. It's not importable, it can't be used with |
Thanks for the explanation. I understand that it's not recommended to put code in Maybe I'm just confused that Go as well as Godoc work well with that scenario (except for the point raised in this issue). In many other places, Go throws compile errors for things that are not recommended. Maybe "Package path must not be empty" would be a reasonable message. But it may break a lot of projects that do what I'm doing here. And these projects will always see a weird page title "Command ." It's not a huge issue so feel free to close it if you feel this case should not be handled. Personally, I think a small addition here could do the trick: if tabtitle == "" {
tabtitle = "main"
} |
Instead of twisting the Go tool to support things it does not support for good reasons just mkdir $GOPATH/src/tmp and put any throwaway code there. |
I don't think that would be a good change to do - the package name could be something other than I think falling back to the package name when the package path is I'm not going to close this issue myself, because I'm not certain as to what degree the "root" package path is supported and supposed to work. Hopefully someone can come with a link that clarifies things one way or another. Otherwise, I'm not convinced that there's anything to fix in godoc here. |
Actually, the package name is if info.IsMain {
// assume that the directory name is the command name
_, tabtitle = pathpkg.Split(relpath)
title = "Command "
} else {
title = "Package "
} Further up, you will find: info.IsMain = pkgname == "main" |
Ah, my bad for misreading the code. The second part of my reply still stands, though. |
This is kind of an edge case with no clear solution. While the Go docs does not explicitly forbid code inside the I would go further to say that the word "Command" is itself misleading for the package root at I would prefer to rename the title to "Root" or something similar. But keeping in mind that the docs suggest to create a folder, it might just be better to leave it as is and close the issue. |
I like the idea of displaying "Root". Eventually, someone who hasn't seen the recommendation will wonder about it again. I don't see the harm in making it work for that edge case. |
I have no opinions either way. Somebody else will have to take a call. Needs a |
What version of Go are you using (
go version
)?go version go1.9.2 darwin/amd64
Does this issue reproduce with the latest release?
Yes.
What did you do?
godoc -http=:6060
http://localhost:6060/pkg/
What did you expect to see?
The page title should say "Command main."
What did you see instead?
It says "Command ."
If the "main" package is in a subdirectory of "src", e.g. "src/main/main.go", it will say "Command main". I typically keep the main function of my application in the "src" directory (which I don't think is very uncommon). The nice thing is also that the main package page will show my application's documentation (that of package "main"). But Godoc will not recognize the command name.
I checked the code. It takes the command name from the page URL (minus the "pkg"). In this case, it's an empty URL so it ends up with an empty string. I think it makes sense to handle this special case and use the string "main" (this applies only if "IsMain" is
true
anyway).Thoughts?
Edit: By "src", I mean "$GOPATH/src".
The text was updated successfully, but these errors were encountered: