You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# ADR-38946: Use Cobra's `Example:` Field for Command Usage Examples
2
+
3
+
**Date**: 2026-06-12
4
+
**Status**: Draft
5
+
6
+
## Context
7
+
8
+
The CLI in `pkg/cli/` defines ~36 cobra commands, and historically every command embedded its usage examples as hand-written prose inside the `Long:` description field under an `Examples:` heading. Cobra provides a dedicated `Example:` field that is rendered separately in `--help` output and, critically, is consumed by `cobra/doc.GenMarkdownTree()` for documentation generation. Because the examples lived inside `Long:`, generated documentation could not surface them in the expected structured location, and the examples were not addressable for testing or tooling. This PR migrates all command definitions to use the native `Example:` field. The change is large by line count but mechanical and repetitive (moving example blocks between two struct fields).
9
+
10
+
## Decision
11
+
12
+
We will store all cobra command usage examples in the native cobra `Example:` field rather than embedding them as `Examples:` prose inside the `Long:` field. Non-example prose that previously followed the `Examples:` section (e.g., "Workflow specifications:", "The command will:") is moved back into `Long:` where it belongs. Tests that previously asserted example strings appeared in `cmd.Long` are updated to assert against `cmd.Example`. This aligns the codebase with cobra's intended API contract, restores correct `GenMarkdownTree()` documentation output, and makes examples independently inspectable.
13
+
14
+
## Alternatives Considered
15
+
16
+
### Alternative 1: Keep examples in `Long:` prose
17
+
18
+
Leave the existing convention untouched and continue embedding examples under an `Examples:` heading inside `Long:`. Rejected because it breaks `cobra/doc.GenMarkdownTree()` documentation generation, keeps examples untestable as a distinct field, and diverges from cobra's documented usage of the `Example:` field.
19
+
20
+
### Alternative 2: Custom help template / renderer
21
+
22
+
Introduce a custom cobra help/usage template that parses the `Examples:` section out of `Long:` at render time. Rejected as unnecessary complexity: it reimplements behavior cobra already provides natively, adds a maintenance burden, and still would not feed `GenMarkdownTree()` correctly.
23
+
24
+
## Consequences
25
+
26
+
### Positive
27
+
-`cobra/doc.GenMarkdownTree()` produces correct documentation with examples in their structured location.
28
+
- Examples become independently testable and inspectable via `cmd.Example`.
29
+
- Command definitions follow cobra's intended API convention, improving consistency across all ~36 commands.
30
+
31
+
### Negative
32
+
- Large, repetitive diff (36 command files plus 8 secondary prose fixes and 5 test updates) that touches many files at once and must be reviewed for correctness.
33
+
- A standing convention contributors must remember to follow for new commands; without a lint check, regressions can reappear.
34
+
35
+
### Neutral
36
+
-`--help` output formatting shifts slightly because the `Example:` field is rendered under cobra's own "Examples:" section heading rather than inline within the long description.
37
+
- Test assertions referencing example content move from `cmd.Long` to `cmd.Example`.
38
+
39
+
---
40
+
41
+
*This is a DRAFT ADR generated by the [Design Decision Gate](https://github.com/github/gh-aw/actions/runs/27447688258) workflow. The PR author must review, complete, and finalize this document before the PR can merge.*
Short: "Deploy agentic workflows to a target repository using a pull request",
29
29
Long: `Deploy one or more workflows to a target repository by combining clone, update, add, compile, and pull request creation.
30
30
31
-
The command clones the target repository, updates existing workflows from source, adds the specified workflows, recompiles lock files with purge enabled, and opens a pull request.
The command clones the target repository, updates existing workflows from source, adds the specified workflows, recompiles lock files with purge enabled, and opens a pull request.`,
0 commit comments