How is Cobra's doc.GenMan called, who writes the man header, and where does static analysis stop?

Short answer

At pinned commit e392f32, doc_test.ExampleGenMan calls doc.GenMan at doc/man_examples_test.go:33, and doc.GenManTreeFromOpts calls GenMan directly at doc/man_docs.go:78. GenMan is defined at line 104 and calls fillHeader at line 108 with cmd.DisableAutoGenTag.

fillHeader at line 117 constructs the man header and honors DisableAutoGenTag. GenMan then evaluates w.Write(md2man.Render(b)) at line 113, but w is an io.Writer interface: static source analysis cannot determine the concrete runtime writer or the complete caller set, so the diagram ends at an explicit unknown boundary.

Pinned-commit evidence

Every evidence link below is bound to spf13/cobra commit e392f3204db0445f1f4ad47448b04d8c8ad04c2a and points to an exact line or range.

Open the offline interactive artifact · Inspect the JSON source · Open the pinned commit ↗

FromToEvidence kindFinding and permalinks
doc_test.ExampleGenMan doc.GenMan direct call

The example calls doc.GenMan(cmd, header, out).

doc/man_examples_test.go#L33
doc.GenManTreeFromOpts doc.GenMan direct internal call

The tree generator returns GenMan(cmd, &headerCopy, f).

doc/man_docs.go#L78
doc.GenMan orchestration definition

GenMan accepts *cobra.Command, *GenManHeader, and io.Writer.

doc/man_docs.go#L104
doc.GenMan fillHeader direct call

GenMan passes cmd.DisableAutoGenTag into fillHeader.

doc/man_docs.go#L108
doc.GenMan md2man.Render / w.Write render + interface write

GenMan renders the generated man body and writes it to io.Writer.

doc/man_docs.go#L113
fillHeader man header header construction

fillHeader builds the header and respects DisableAutoGenTag.

doc/man_docs.go#L117
md2man.Render / w.Write concrete io.Writer target static unknown

The runtime writer implementation and complete downstream caller set cannot be resolved from this interface call.

doc/man_docs.go#L113

Boundaries that mislead

Known caller set is finite, not exhaustive

The example at line 33 and tree generator at line 78 are verified direct references. Other tests and downstream consumers may call the exported API, so these two arrows must not be read as a complete whole-program caller graph.

doc/man_examples_test.go#L33doc/man_docs.go#L78

Static unknown: concrete io.Writer target

The io.Writer parameter is interface-typed. Source inspection proves the Write call site, but it cannot select a concrete implementation, prove the final filesystem path, or enumerate every runtime caller. The dashed edge is deliberately unresolved.

doc/man_docs.go#L113

Calls and ownership

1. Two verified ways into GenMan

The external example passes a bytes.Buffer named out to doc.GenMan. The internal tree generator opens a file, copies the supplied header, and passes that file to GenMan. These are two observed call sites, not proof that no other callers exist in downstream programs.

2. GenMan owns orchestration; fillHeader owns header policy

GenMan normalizes a nil header, calls fillHeader with the command and its DisableAutoGenTag value, then generates the man body. fillHeader is the function that constructs the header fields and decides whether the automatic generation tag is included.

3. Rendering is known; interface dispatch is not

The expression w.Write(md2man.Render(b)) establishes that Markdown is rendered before the bytes are handed to io.Writer.Write. It does not reveal the dynamic type of w. A buffer, an open file, a network wrapper, or a downstream custom writer are all compatible with the static signature.

What this proves — and what it does not

  • This article is independent static source analysis, not an endorsement by the Cobra maintainers. Conclusions are limited to spf13/cobra commit e392f3204db0445f1f4ad47448b04d8c8ad04c2a.
  • The two shown callers are verified source references, not a complete caller set for the exported API. Downstream callers and runtime-selected implementations are outside the fixed repository evidence.
  • The final io.Writer implementation, filesystem destination, write success, permissions, and runtime side effects are unknown. The diagram does not claim that GenMan always writes a file or always writes to stdout.
  • The source anchors establish call structure and header policy; they do not prove generated man-page correctness for every command tree or Cobra version.

Reuse with your agent

Give an agent the pinned commit and this review prompt; require it to open every permalink and keep unknowns explicit.

Audit only spf13/cobra commit e392f3204db0445f1f4ad47448b04d8c8ad04c2a. Trace ExampleGenMan:33 and GenManTreeFromOpts:78 into GenMan:104, show fillHeader:117 receiving DisableAutoGenTag from line 108, and stop at w.Write(md2man.Render(b)):113 with a dashed static-unknown io.Writer edge. Never invent a concrete writer, filesystem path, or complete caller set.
Cite this source case in Markdown
[Cobra GenMan Call Graph and io.Writer Boundary](https://archify.si/cases/cobra-genman)

Archify independent static source analysis, limited to the pinned commit.

Start with the architecture diagram type →