Closed dominikbraun closed 3 years ago
Cobra includes command generation. Here are the docs: https://github.com/spf13/cobra/blob/master/doc/README.md https://github.com/spf13/cobra/blob/master/doc/md_docs.md
I will definitely play with that a bit and get back here!
I tried generating some docs, and it works:
Generated docs:
Index documentation
Document of a command
Documentation of a subcommand
Steps to generate documentation
main
function from main.go
, but with some modifications
package main
import ( "log"
"github.com/dominikbraun/timetrace/cli"
"github.com/dominikbraun/timetrace/config"
"github.com/dominikbraun/timetrace/core"
"github.com/dominikbraun/timetrace/fs"
"github.com/dominikbraun/timetrace/out"
"github.com/spf13/cobra/doc"
)
var version = "UNDEFINED"
func main() { c, err := config.FromFile() if err != nil { out.Warn("%s", err.Error()) }
filesystem := fs.New(c)
timetrace := core.New(c, filesystem)
cmd := cli.RootCommand(timetrace, version)
err = doc.GenMarkdownTree(cmd, "./docs")
if err != nil {
log.Fatal(err)
}
}
3. Running that script with `go run` places docs in the `docs` directory in cwd
This was the process. We can incorporate it in CI with a bit of refining. @dominikbraun Any suggestions?
Wow, thanks! This looks exactly like what I've been looking for. I'm going to open some issues for implementing this 😄
I'm going to close this since we found a way to auto-generate docs. The subsequent issue is #87. Thanks again for figuring this out!
I'd love to auto-generate the documentation for commands from the
cobra.Command.Long
help text and the command's options. Maybe there's some cool way to do this?