Skip to content
Merged
Show file tree
Hide file tree
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 May 17, 2026
72cdae5
Add docgen script
thelovekesh May 17, 2026
a74545b
Add docgen scripts
thelovekesh May 17, 2026
d8faceb
Add `!docs`
thelovekesh May 17, 2026
276162a
Add /docs/yaml to ignore list
thelovekesh May 17, 2026
e66aace
Add yaml generation support
thelovekesh May 17, 2026
5f8b4db
Add script to generate docs as yaml
thelovekesh May 17, 2026
274e6c3
Add README for writing docs
thelovekesh May 19, 2026
5bb09ad
Update cli docs path
thelovekesh May 19, 2026
443e97f
Add docs for hand written content
thelovekesh May 19, 2026
1f78f16
Add cli docs
thelovekesh May 19, 2026
2b95b89
Add auth command docs
thelovekesh May 20, 2026
b8c53c4
Add why command docs
thelovekesh May 20, 2026
55a92c0
Add init command docs
thelovekesh May 20, 2026
0bbf417
Add install command docs
thelovekesh May 20, 2026
ca2bc6f
Add ls command docs
thelovekesh May 20, 2026
0358c39
Add publish command docs
thelovekesh May 20, 2026
8407739
Add whoami command docs
thelovekesh May 20, 2026
fe8b6b3
Add uninstall command docs
thelovekesh May 20, 2026
25b35df
Add outdated command docs
thelovekesh May 20, 2026
82fdab0
Add wpm command docs
thelovekesh May 20, 2026
63aceff
Add docs for registry auth
thelovekesh May 20, 2026
613e0c8
Add FAQs
thelovekesh May 20, 2026
d998287
Add docs index page
thelovekesh May 20, 2026
942c403
Add guides
thelovekesh May 20, 2026
1525acb
Add cli installation docs
thelovekesh May 20, 2026
712d835
Add package types docs
thelovekesh May 20, 2026
aa8e01e
Add wpm.json docs
thelovekesh May 20, 2026
b293a00
Add wpm.lock docs
thelovekesh May 20, 2026
28f406c
Add wpmignore docs
thelovekesh May 20, 2026
6d19b74
Add registry docs
thelovekesh May 20, 2026
8a63a9d
Add glossary
thelovekesh May 20, 2026
fc7f7d3
Format markdown files
thelovekesh May 22, 2026
029ee23
Update token url
thelovekesh May 22, 2026
cdbc5d8
Add important notes
thelovekesh May 22, 2026
b07eaf6
Add main docs page
thelovekesh May 22, 2026
3a4ca1b
Add publishing guide
thelovekesh May 22, 2026
ef69616
Remove redundant notes
thelovekesh May 22, 2026
8cee895
Add more refs
thelovekesh May 22, 2026
aaae32a
Fix GFM blockquote rendering
thelovekesh May 22, 2026
19c2389
Disable oxfmt formatting on auto-generated docs
thelovekesh May 22, 2026
ad27df1
Consolidate docs and reduce multiple sources of truth
thelovekesh May 22, 2026
6e43dc4
Refine docs
thelovekesh May 22, 2026
b5a2d10
Move cli docs to docs/reference/
thelovekesh May 22, 2026
e3eec8a
Update cli docs generation path
thelovekesh May 22, 2026
dcad5de
Fix cli docs path
thelovekesh May 22, 2026
1d3da14
Update docs structure
thelovekesh May 22, 2026
dbba684
Move docs landing page to overview
thelovekesh May 22, 2026
0dbd6ff
Fix paths
thelovekesh May 22, 2026
f9ba641
Update doc for limiting and deps and devDeps to 16 items limit
thelovekesh May 22, 2026
af74ee2
Update wording
thelovekesh May 22, 2026
33e6f21
Add active development note
thelovekesh May 22, 2026
9979eda
Add why wpm page
thelovekesh May 22, 2026
fcb7139
Fix the config flag default value
thelovekesh May 22, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
/docs/yaml/
/cmd/wpm/winresources/versioninfo.json
/cmd/wpm/winresources/*.syso

Expand All @@ -21,6 +22,7 @@
# directories
!cli
!cmd
!docs
!pkg
!.vscode
!install
Expand Down
161 changes: 161 additions & 0 deletions cmd/docgen/docgen.go
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")
}
Comment thread
thelovekesh marked this conversation as resolved.
Resolved
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
}
172 changes: 172 additions & 0 deletions docs/README.md
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.
Loading