feat: add --mintlify flag to kosli docs command#663
Conversation
Introduce internal/docgen package with a Formatter interface and two implementations (HugoFormatter, MintlifyFormatter) so the CLI can directly generate Mintlify-compatible MDX documentation. - Extract doc rendering logic from cmd/kosli/docs.go into docgen - Add MintlifyFormatter with <Warning>, <Tabs>/<Tab>, <AccordionGroup>/<Accordion> components, JSX escaping, and relative URLs - Move CommandsInTable and helpers to docgen/helpers.go - Add GenMarkdownTree tree walker using Formatter + callbacks - Wire --mintlify flag in docsOptions to select formatter - Add golden file tests for both Mintlify snyk and artifact pages - Existing Hugo golden file test unchanged (no regression)
Move Hugo golden files from testdata/output/docs/ to testdata/output/docs/hugo/ for symmetry with mintlify/. Hugo golden file content is unchanged. Add Mintlify golden file comparison tests for snyk and deprecated artifact commands. Update Hugo test golden path only.
Mintlify renders the front matter title as h1 automatically, so the generated docs should not include a duplicate # heading. Add Title() method to Formatter interface — Hugo emits # name, Mintlify returns empty string. Pages now start with ## Synopsis.
Replace bare https://docs.kosli.com/path URLs in Mintlify output with markdown links [docs](/path) so they are clickable both locally (mint dev) and when deployed. Applies to flag descriptions and synopsis text.
TestsCurrent Hugo docsI have tested and compared the creation of Hugo CLI docs. By first running mkdir tmp
DOCS=true go run ./cmd/kosli docs --dir tmpOn the feature branch. All files are identical MintlifyIn the DOCS=true go run <path to cli repo>/cmd/kosli docs --dir mintlify --mintlifyon a path that was covered by All files looks correct. |
There was a problem hiding this comment.
Pull request overview
This pull request adds a --mintlify flag to the kosli docs command to generate Mintlify-compatible MDX documentation alongside the existing Hugo markdown format. The implementation introduces a new internal/docgen package that extracts and refactors the documentation generation logic into a clean, interface-based architecture.
Changes:
- Introduces
internal/docgenpackage withFormatterinterface implemented byHugoFormatterandMintlifyFormatter - Converts bare
https://docs.kosli.com/pathURLs in flag descriptions to clickable markdown links in Mintlify output - Refactors existing Hugo documentation generation to use the new architecture while maintaining backward compatibility
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/docgen/formatter.go | Defines Formatter interface and related types (CommandMeta, CIExample, LiveDocProvider) |
| internal/docgen/hugo.go | Hugo formatter implementation (extracted from cmd/kosli/docs.go) |
| internal/docgen/mintlify.go | New Mintlify formatter with MDX components and JSX escaping |
| internal/docgen/helpers.go | Shared helper functions (CommandsInTable, HashTitledExamples, etc.) moved from cmd/kosli |
| internal/docgen/generate.go | Main generation logic using the Formatter interface |
| internal/docgen/*_test.go | Comprehensive unit tests for formatters and helpers |
| cmd/kosli/docs.go | Refactored to use internal/docgen package with new --mintlify flag |
| cmd/kosli/docs_test.go | Updated tests with new golden file paths and Mintlify test cases |
| cmd/kosli/testdata/output/docs/hugo/* | Hugo golden files for testing (relocated from previous path) |
| cmd/kosli/testdata/output/docs/mintlify/* | New Mintlify golden files for testing |
| cmd/kosli/printCommandsInTable.go | Removed (functionality moved to internal/docgen/helpers.go with modernization) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
--mintlifyflag tokosli docscommand to generate Mintlify-compatible MDX documentation directly from the CLIinternal/docgenpackage with aFormatterinterface, implemented byHugoFormatter(existing behavior) andMintlifyFormatter(new)https://docs.kosli.com/pathURLs in flag descriptions to clickable[docs](/path)markdown links in Mintlify outputDetails
New package
internal/docgen/extracts doc generation logic fromcmd/kosli/docs.gointo a clean architecture:cmd/kosli(isBeta/isDeprecated) with docgenMintlify-specific features:
description:(sanitized, truncated) instead ofsummary:<Warning>,<Tabs>/<Tab>,<AccordionGroup>/<Accordion>components instead of Hugo shortcodes{expr}and<WORD>patterns outside code fencesTest plan
go test ./internal/docgen/...— all new unit tests passgo test ./cmd/kosli/... -run TestDocsCommandTestSuite— Hugo golden file unchangedCloses #662