Repository navigation
Add docs generator and initial generated documentation #228
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
Merged
Merged
Changes from all commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
fa20996
Add `github.com/docker/cli-docs-tool`
thelovekesh 72cdae5
Add docgen script
thelovekesh a74545b
Add docgen scripts
thelovekesh d8faceb
Add `!docs`
thelovekesh 276162a
Add /docs/yaml to ignore list
thelovekesh e66aace
Add yaml generation support
thelovekesh 5f8b4db
Add script to generate docs as yaml
thelovekesh 274e6c3
Add README for writing docs
thelovekesh 5bb09ad
Update cli docs path
thelovekesh 443e97f
Add docs for hand written content
thelovekesh 1f78f16
Add cli docs
thelovekesh 2b95b89
Add auth command docs
thelovekesh b8c53c4
Add why command docs
thelovekesh 55a92c0
Add init command docs
thelovekesh 0bbf417
Add install command docs
thelovekesh ca2bc6f
Add ls command docs
thelovekesh 0358c39
Add publish command docs
thelovekesh 8407739
Add whoami command docs
thelovekesh fe8b6b3
Add uninstall command docs
thelovekesh 25b35df
Add outdated command docs
thelovekesh 82fdab0
Add wpm command docs
thelovekesh 63aceff
Add docs for registry auth
thelovekesh 613e0c8
Add FAQs
thelovekesh d998287
Add docs index page
thelovekesh 942c403
Add guides
thelovekesh 1525acb
Add cli installation docs
thelovekesh 712d835
Add package types docs
thelovekesh aa8e01e
Add wpm.json docs
thelovekesh b293a00
Add wpm.lock docs
thelovekesh 28f406c
Add wpmignore docs
thelovekesh 6d19b74
Add registry docs
thelovekesh 8a63a9d
Add glossary
thelovekesh fc7f7d3
Format markdown files
thelovekesh 029ee23
Update token url
thelovekesh cdbc5d8
Add important notes
thelovekesh b07eaf6
Add main docs page
thelovekesh 3a4ca1b
Add publishing guide
thelovekesh ef69616
Remove redundant notes
thelovekesh 8cee895
Add more refs
thelovekesh aaae32a
Fix GFM blockquote rendering
thelovekesh 19c2389
Disable oxfmt formatting on auto-generated docs
thelovekesh ad27df1
Consolidate docs and reduce multiple sources of truth
thelovekesh 6e43dc4
Refine docs
thelovekesh b5a2d10
Move cli docs to docs/reference/
thelovekesh e3eec8a
Update cli docs generation path
thelovekesh dcad5de
Fix cli docs path
thelovekesh 1d3da14
Update docs structure
thelovekesh dbba684
Move docs landing page to overview
thelovekesh 0dbd6ff
Fix paths
thelovekesh f9ba641
Update doc for limiting and deps and devDeps to 16 items limit
thelovekesh af74ee2
Update wording
thelovekesh 33e6f21
Add active development note
thelovekesh 9979eda
Add why wpm page
thelovekesh fcb7139
Fix the config flag default value
thelovekesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| // Command docgen renders reference documentation for the wpm CLI by | ||
| // walking the cobra command tree with docker/cli-docs-tool. | ||
| // | ||
| // It can emit three formats: | ||
| // | ||
| // - md — GitHub-flavored Markdown, committed to docs/reference/cli/. | ||
| // The source and target directories are the same: each per-command | ||
| // file is rewritten in place, but only the section between | ||
| // "<!---MARKER_GEN_START--->" and "<!---MARKER_GEN_END--->" is | ||
| // touched. Any prose authored outside the markers (typically the | ||
| // "## Description" and "## Examples" H2 sections) is preserved | ||
| // across regenerations. | ||
| // | ||
| // - man — roff(7) man pages. Build artefact, NOT committed. | ||
| // | ||
| // - yaml — structured per-command data, consumed by the docs site. | ||
| // Each command becomes one YAML file with fields for short, long, | ||
| // usage, options[], examples, cname[]/clink[], plus annotations | ||
| // such as experimental, deprecated, hidden. Build artefact, NOT | ||
| // committed. The docs site converts these to JSON at site-build | ||
| // time before rendering with MDX. | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "log" | ||
| "os" | ||
|
|
||
| "go.wpm.so/cli/cli" | ||
| "go.wpm.so/cli/cli/command" | ||
| "go.wpm.so/cli/cli/command/commands" | ||
| "go.wpm.so/cli/cli/version" | ||
|
|
||
| clidocstool "github.com/docker/cli-docs-tool" | ||
| "github.com/spf13/cobra" | ||
| "github.com/spf13/cobra/doc" | ||
| "github.com/spf13/pflag" | ||
| ) | ||
|
|
||
| const ( | ||
| defaultMdDir = "docs/reference/cli" | ||
| defaultManDir = "man/man1" | ||
| defaultYamlDir = "docs/yaml" | ||
| ) | ||
|
|
||
| type options struct { | ||
| format string | ||
| source string | ||
| target string | ||
| } | ||
|
|
||
| func main() { | ||
| if err := run(); err != nil { | ||
| fmt.Fprintln(os.Stderr, "docgen:", err) | ||
| os.Exit(1) | ||
| } | ||
| } | ||
|
|
||
| func run() error { | ||
| log.SetFlags(0) | ||
|
|
||
| opts, err := parseArgs(os.Args[1:]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| root, err := newWpmRoot() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := os.MkdirAll(opts.target, 0o755); err != nil { | ||
| return fmt.Errorf("create %s: %w", opts.target, err) | ||
| } | ||
|
|
||
| toolOpts := clidocstool.Options{ | ||
| Root: root, | ||
| SourceDir: opts.source, | ||
| TargetDir: opts.target, | ||
| } | ||
| if opts.format == "man" { | ||
| toolOpts.ManHeader = &doc.GenManHeader{ | ||
| Title: "wpm", | ||
| Section: "1", | ||
| Source: "wpm " + version.Version, | ||
| Manual: "wpm Manual", | ||
| } | ||
| } | ||
|
|
||
| tool, err := clidocstool.New(toolOpts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| switch opts.format { | ||
| case "md": | ||
| return tool.GenMarkdownTree(root) | ||
| case "man": | ||
| return tool.GenManTree(root) | ||
| case "yaml": | ||
| return tool.GenYamlTree(root) | ||
| default: | ||
| return fmt.Errorf("unsupported format %q (want md, man, or yaml)", opts.format) | ||
| } | ||
| } | ||
|
|
||
| func parseArgs(args []string) (options, error) { | ||
| var opts options | ||
|
|
||
| fs := pflag.NewFlagSet("docgen", pflag.ContinueOnError) | ||
| fs.StringVar(&opts.format, "format", "md", "Output format: md, man, or yaml") | ||
| fs.StringVar(&opts.source, "source", "", "Source directory (defaults to "+defaultMdDir+")") | ||
| fs.StringVar(&opts.target, "target", "", "Target directory (defaults: "+defaultMdDir+" for md, "+defaultManDir+" for man, "+defaultYamlDir+" for yaml)") | ||
|
|
||
| if err := fs.Parse(args); err != nil { | ||
| return opts, err | ||
| } | ||
|
|
||
| if opts.source == "" { | ||
| opts.source = defaultMdDir | ||
| } | ||
| if opts.target == "" { | ||
| switch opts.format { | ||
| case "md": | ||
| opts.target = opts.source | ||
| case "man": | ||
| opts.target = defaultManDir | ||
| case "yaml": | ||
| opts.target = defaultYamlDir | ||
| } | ||
| } | ||
| if opts.format == "" { | ||
| return opts, errors.New("--format is required") | ||
| } | ||
| return opts, nil | ||
| } | ||
|
|
||
| // newWpmRoot creates the root cobra.Command for the wpm CLI, with all | ||
| // subcommands registered. This is used by docgen to generate documentation | ||
| // for the entire command tree. | ||
| func newWpmRoot() (*cobra.Command, error) { | ||
| wpmCli, err := command.NewWpmCli() | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| cmd := &cobra.Command{ | ||
| Use: "wpm [OPTIONS] COMMAND [ARG...]", | ||
| Short: "Package Manager for WordPress ecosystem", | ||
| DisableAutoGenTag: true, | ||
| DisableFlagsInUseLine: true, | ||
| } | ||
|
|
||
| cli.SetupRootCommand(cmd) | ||
| commands.AddCommands(cmd, wpmCli) | ||
| cli.DisableFlagsInUseLine(cmd) | ||
|
|
||
| return cmd, nil | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| # Writing wpm docs | ||
|
|
||
| Every command in `cli/command/` has a matching reference file in `docs/cli/`. | ||
|
|
||
| Nested commands use underscores: | ||
|
|
||
| - `wpm auth` → `docs/cli/auth.md` | ||
| - `wpm auth login` → `docs/cli/auth_login.md` | ||
|
|
||
| ## File structure | ||
|
|
||
| Each reference file has two regions: | ||
|
|
||
| ```markdown | ||
| # wpm install | ||
|
|
||
| <!---MARKER_GEN_START--> | ||
|
|
||
| (auto-generated: Short, Aliases, Options, Subcommands table) | ||
|
|
||
| <!---MARKER_GEN_END--> | ||
|
|
||
| ## Description | ||
|
|
||
| (hand-written prose) | ||
|
|
||
| ## Examples | ||
|
|
||
| (hand-written shell sessions) | ||
| ``` | ||
|
|
||
| ### Auto-generated region | ||
|
|
||
| Everything between: | ||
|
|
||
| ```html | ||
| <!---MARKER_GEN_START--> | ||
| <!---MARKER_GEN_END--> | ||
| ``` | ||
|
|
||
| is generated by `./scripts/docs/generate-md`. | ||
|
|
||
| Do not edit this section by hand. | ||
|
|
||
| To change: | ||
|
|
||
| - aliases | ||
| - option defaults | ||
| - command metadata | ||
| - flag descriptions | ||
|
|
||
| edit the Go source under `cli/command/<name>/` and regenerate the docs. | ||
|
|
||
| ### Hand-written region | ||
|
|
||
| Everything outside the markers is preserved across regenerations. | ||
|
|
||
| Write all explanatory content here, including: | ||
|
|
||
| - caveats | ||
| - examples | ||
| - workflows | ||
| - troubleshooting notes | ||
| - conceptual explanations | ||
|
|
||
| ## Supported sections | ||
|
|
||
| The docs generator reads exactly two sections from each file: | ||
|
|
||
| | Section | Output | | ||
| | ---------------- | ----------------- | | ||
| | `## Description` | Main body content | | ||
| | `## Examples` | Examples section | | ||
|
|
||
| Additional top-level sections are ignored by the docs site and manpage | ||
| generator. | ||
|
|
||
| For example: | ||
|
|
||
| - `## Notes` | ||
| - `## Caveats` | ||
| - `## See also` | ||
|
|
||
| still appear on GitHub, but are not included in generated output. | ||
|
|
||
| Use nested headings inside `## Description` when needed: | ||
|
|
||
| ```markdown | ||
| ## Description | ||
|
|
||
| ### Authentication flow | ||
|
|
||
| #### Token storage | ||
| ``` | ||
|
|
||
| Avoid introducing new top-level `##` sections. | ||
|
|
||
| ## Workflow | ||
|
|
||
| 1. Add or modify the `cobra.Command` in `cli/command/<name>/`. | ||
|
|
||
| 2. Run: | ||
|
|
||
| ```sh | ||
| ./scripts/docs/generate-md | ||
| ``` | ||
|
|
||
| 3. Edit: | ||
| - `## Description` | ||
| - `## Examples` | ||
|
|
||
| in `docs/cli/<name>.md`. | ||
|
|
||
| 4. Commit the Go changes and Markdown updates together. | ||
|
|
||
| ## Verifying generated output | ||
|
|
||
| After editing docs, regenerate all derived artifacts: | ||
|
|
||
| ```sh | ||
| ./scripts/docs/generate-md | ||
| ./scripts/docs/generate-yaml | ||
| ``` | ||
|
|
||
| Then inspect the generated YAML: | ||
|
|
||
| ```text | ||
| docs/yaml/wpm_<command>.yaml | ||
| ``` | ||
|
|
||
| Verify that: | ||
|
|
||
| - `long:` contains the `## Description` content | ||
| - `examples:` contains the `## Examples` content | ||
|
|
||
| If either field is empty: | ||
|
|
||
| - the heading may be misspelled | ||
| - the heading level may be incorrect | ||
| - the section may be inside the generated marker block | ||
|
|
||
| Fix the Markdown and regenerate. | ||
|
|
||
| ## Other reference docs | ||
|
|
||
| Non-CLI topics live in their own directories under `docs/`. | ||
|
|
||
| Each topic directory contains an `index.md` overview plus any related pages: | ||
|
|
||
| ```text | ||
| docs/ | ||
| ├── README.md | ||
| ├── cli/ | ||
| ├── wpm-json/ | ||
| │ ├── index.md | ||
| │ ├── dependencies.md | ||
| │ └── scripts.md | ||
| └── wpmignore/ | ||
| ├── index.md | ||
| └── patterns.md | ||
| ``` | ||
|
|
||
| These files are plain Markdown. | ||
|
|
||
| Unlike CLI reference docs: | ||
|
|
||
| - there are no generated marker blocks | ||
| - there is no regeneration workflow | ||
| - content is edited entirely by hand | ||
|
|
||
| Use these directories for conceptual documentation, specifications, guides, and | ||
| other non-command reference material. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.