Skip to content
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

cmd/doc: support 'go doc package@version' syntax #63696

Open
adonovan opened this issue Oct 23, 2023 · 7 comments
Open

cmd/doc: support 'go doc package@version' syntax #63696

adonovan opened this issue Oct 23, 2023 · 7 comments

Comments

@adonovan
Copy link
Member

adonovan commented Oct 23, 2023

The go doc command displays documentation for packages in the workspace, but it would be very useful if it also worked on packages (and commands in particular) that are not part of the workspace, using an @version suffix. The implementation would consult the module cache, populating it as needed. For example:

$ go doc go.starlark.net/syntax@latest
go: downloading go.starlark.net v0.0.0-20231016134836-22325403fcb3
go: added go.starlark.net v0.0.0-20231016134836-22325403fcb3
package syntax // import "go.starlark.net/syntax"

Package syntax provides a Starlark parser and abstract syntax tree.
...

@rsc made the suggestion that the version suffix could be inferred if the package name was not part of the workspace, if it matched the name of a command on $PATH, and that command was a Go executable, and the metadata inside that Go executable provided a module@version provenance string.

@bcmills
Copy link
Contributor

bcmills commented Oct 23, 2023

the version suffix could be inferred if the package name was not part of the workspace, if it matched the name of a command on $PATH, and that command was a Go executable, and the metadata inside that Go executable provided a module@version provenance string.

That sounds like an awful lot of magic. 😅

For the specific case of printing a version in a usage string, perhaps we could provide a helper function somewhere that uses runtime/debug.ReadBuildInfo to produce a path@version string for the current binary? That could be used in both a usage message and a --version flag, so that users could run something like go doc $(syntax --version).

Or, perhaps go version itself should have a flag that prints that form? Then users could run go doc $(go version -main $(which syntax)).

@earthboundkid
Copy link
Contributor

For the specific case of printing a version in a usage string, perhaps we could provide a helper function somewhere that uses runtime/debug.ReadBuildInfo to produce a path@version string for the current binary? That could be used in both a usage message and a --version flag, so that users could run something like go doc $(syntax --version).

FWIW, I wrote a module which looks at runtime/debug.ReadBuildInfo for CLI usage screens, but it would be nicer to have it built in somewhere.

@rsc
Copy link
Contributor

rsc commented Oct 27, 2023

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc
Copy link
Contributor

rsc commented Nov 8, 2023

Sounds like this is a likely accept, but the implementation will probably be tricky, so let's leave it for Go 1.23.

@rsc
Copy link
Contributor

rsc commented Nov 10, 2023

I don't think we discussed whether it is possible to add @version to go doc pkg.symbol, and if so how.
I think these two would work:

go doc golang.org/x/tools/txtar.FS@v0.13.0
go doc golang.org/x/tools/txtar@v0.13.0 FS

and this would be rejected:

go doc golang.org/x/tools/txtar@v0.13.0.FS

After more discussion with @bcmills, I've realized that making this change the right way is going to require significant reworking of the existing machinery. Please don't send CLs. We'll take care of it. Thanks.

@rsc
Copy link
Contributor

rsc commented Nov 10, 2023

Based on the discussion above, this proposal seems like a likely accept.
— rsc for the proposal review group

go doc would change to accept an @version suffix on its first argument, so these all become valid:

go doc txtar@v0.13.0
go doc txtar@v0.13.0 FS
go doc txtar.FS@v0.13.0
go doc golang.org/x/tools/txtar@v0.13.0
go doc golang.org/x/tools/txtar@v0.13.0 FS
go doc golang.org/x/tools/txtar.FS@v0.13.0

@rsc
Copy link
Contributor

rsc commented Nov 16, 2023

No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— rsc for the proposal review group

go doc would change to accept an @version suffix on its first argument, so these all become valid:

go doc txtar@v0.13.0
go doc txtar@v0.13.0 FS
go doc txtar.FS@v0.13.0
go doc golang.org/x/tools/txtar@v0.13.0
go doc golang.org/x/tools/txtar@v0.13.0 FS
go doc golang.org/x/tools/txtar.FS@v0.13.0

@rsc rsc changed the title proposal: cmd/doc: support 'go doc package@version' syntax cmd/doc: support 'go doc package@version' syntax Nov 16, 2023
@rsc rsc modified the milestones: Proposal, Backlog Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Accepted
Development

No branches or pull requests

5 participants