cmddocs

command
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 8 Imported by: 0

README

internal/cmddocs

Walks the declarative cmd.Root tree and emits command descriptions, flags, examples, output metadata, and typed errors as JSON. The generator in docs.baseten.co uses this metadata to build CLI reference snippets and page drafts.

Run this developer tool from a checkout of the release being documented. It does not load credentials or execute CLI commands.

Output contract

The JSON shape is defined by the Go types in schema.go. The top-level schema_version field is "1"; bump SchemaVersion in schema.go whenever an existing field is removed or its meaning changes (adding a new optional field does not require a bump).

group_pri is emitted verbatim: 0 means the flag set no group-pri, and the consumer applies the framework default (DefaultFlagGroupPri = 100). The walker does not resolve it.

The emitter preserves the complete declared command tree, including hidden commands and flags. Public reference generators must exclude commands marked hidden, their descendants, and flags marked hidden. Keeping this metadata lets consumers follow the visibility declared by the CLI's authors.

Optional metadata fields are omitted when unset:

  • hidden marks commands and flags excluded from public help.
  • nullable means a flag accepts the literal null, including when its enum lists only non-null values.
  • json_output_unimportant marks commands without meaningful JSON output.
  • json_alternatives lists additional output types and the input selecting each one. Each entry contains when and json_output_type.

Output types are Go type names, not JSON field schemas. For streamed commands, json_array_streamed means the type describes one record. Examples use the same command text as the CLI, joining multiline declarations into one line.

Running locally

# Write to stdout (default).
go run ./internal/cmddocs --cli-version=dev

# Write to a file.
go run ./internal/cmddocs --cli-version=v0.1.0 --out=docs.json

# Reproducible timestamp.
SOURCE_DATE_EPOCH=1700000000 go run ./internal/cmddocs --cli-version=v0.1.0 --out=docs.json

Tests

go test ./internal/cmddocs/...

Tests cover metadata extraction, the real command tree, file and stdout output, reproducible timestamps, and error handling. They run with the repository's normal Go tests. There is no generated snapshot to keep in sync.

How docs.baseten.co consumes this

Docs maintainers check out a released CLI tag and run go run ./internal/cmddocs --cli-version=<tag> --out=docs.json. In the docs checkout, they pass the file to bin/generate_baseten_cli_docs.py and review the generated changes before publishing. Generation is a manual maintenance step. Nothing in this repo's release flow runs the emitter or publishes docs.json.

Documentation

Overview

Command cmddocs walks the declarative cmd.Root tree and emits a versioned JSON description for consumption by docs.baseten.co. Docs maintainers run it from a CLI release checkout; nothing in this repo's release flow runs it.

Usage:

go run ./internal/cmddocs --cli-version=v0.1.0 --out=docs.json
go run ./internal/cmddocs --cli-version=dev          # writes to stdout

Set SOURCE_DATE_EPOCH (Unix seconds) to pin GeneratedAt for reproducible output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL