Description
If I'm shipping a Go binary, generally, I need to add documentation in three different places:
-
a README or README.md file, for people visiting the project via Github. This contains usage information and usually also installation information
-
in
doc.go
or similar, so it appears via godoc. Some go tools document this well, but many tools fall down on the docs here:- https://godoc.org/github.com/golang/dep/cmd/dep
- https://godoc.org/golang.org/x/build/maintner/maintnerd
- https://godoc.org/golang.org/x/build/cmd/gopherbot
- https://godoc.org/github.com/kubernetes/kubernetes/cmd/kubectl
- https://godoc.org/github.com/moby/moby/cmd/docker
- https://godoc.org/github.com/spf13/hugo
-
in
flag.Usage
, so it looks nice when printed at the command line, and shows you the various arguments you can run.
It's a shame that maintainers have to more or less write the same docs in triplicate, and a bad experience for our users when they forget to do so in one or more of the places above.
I also wonder if this discourages contribution, when people get to a Github source code page and the results are clearly not formatted for browsing on that site.
I'm wondering what we can do to ease the burden on maintainers, or make it easy to copy docs from one place to another. I understand that the audiences for each documentation place overlap in parts and don't overlap in other parts, but I imagine some docs are better than nothing. Here are some bad ideas:
-
If a
main
function has no package docs, but modifiesflag.CommandLine
, godoc could callflag.PrintDefaults
, or call the binary with-h
and then print the result. Note the godoc docs linked above manually copy the output from flag.PrintDefaults and it occasionally gets out of sync. -
If a
main
function has no package docs but has a README.md,godoc
could format README.md and ignore the parts of the markdown spec that we don't want to implement. -
We could try to get Github to understand and display Go code, the same way it can currently display a number of formats like Restructured Text, ASCIIDOC, Creole, RDoc, textile and others.