feat(docs): generate Commands section of README from cobra metadata - #765
Draft
ewanharris wants to merge 1 commit into
Draft
ewanharris wants to merge 1 commit into
ewanharris wants to merge 1 commit into
Conversation
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Introduce a code generator (cmd/gendocs) that walks the cobra command
tree and splices a fresh Commands section and table-of-contents block
into README.md. Command descriptions, parameters, examples, and
response samples are sourced directly from each command's Long,
Example, and Annotations fields, making the cobra definition the
single source of truth.
A make generate-docs target runs the generator. A CI step
("Check README commands section is up to date") fails the build if
the committed README doesn't match the generated output, so drift is
caught on every PR.
To populate the generated output, Long, Example, and docs:response /
docs:response:lang annotation fields were added to all store, model,
tuple, and query commands. docs:response:lang controls the fence
language for non-JSON responses (yaml for store export, fga for model
get and transform, text for model test).
Commands are ordered alphabetically (cobra's Commands() order).
Top-level runnables (version) are excluded from both the body and
the TOC — they have no group heading.
ewanharris
force-pushed
the
worktree-feat+generate-commands-docs
branch
from
September 18, 2026 15:10
ffb59a2 to
6b7350f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
What problem is being solved?
The Commands section of README.md was hand-rolled and had drifted out of sync with the actual CLI — commands were missing, examples were outdated, and there was no mechanism to catch regressions.
How is it being solved?
A code generator (
cmd/gendocs) walks the cobra command tree and splices a fresh Commands section and table-of-contents block into README.md. Command descriptions, parameters, examples, and response samples are sourced directly from each command'sLong,Example, andAnnotationsfields, making the cobra definition the single source of truth.A
make generate-docstarget runs the generator, and a new CI step fails the build if the committed README doesn't match the generated output, so drift is caught on every PR.What changes are made to solve it?
internal/doc: new package containing the generator and splice logic, with testscmd/gendocs/main.go: entrypoint that wires the root command into the generatorMakefile: generate-docs target.github/workflows/main.yaml: Check README commands section is up to date CI stepLong,Example, anddocs:response/docs:response:langannotation fields added to all store, model, tuple, and query commands to populate the generated outputREADME.md: Commands section and ToC block wrapped with splice markers; content regeneratedOne change from this is that commands are now ordered alphabetically (cobra's
Commands()order), so the generated section reads Authorization Models -> Manage JSON-to-tuple mappings -> Relationship Queries -> Stores -> Relationship Tuples rather than the previous hand-written order that kind of followed the natural flow of usage. Top-level runnables (version) are excluded from both the body and the ToC as they have no group heading.References
This is inspired by similar functionality in auth0-cli that is used to build the website for it.
Review Checklist
main