Migrate cobra command examples from Long: prose to Example: field#38946
Conversation
Co-authored-by: pelikhan <[email protected]>
Co-authored-by: pelikhan <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR migrates CLI usage examples across pkg/cli/ from hand-written “Examples:” prose embedded in cobra.Command.Long into Cobra’s dedicated cobra.Command.Example field, improving cobra/doc.GenMarkdownTree() doc generation and making examples easier to validate in tests.
Changes:
- Moved command examples out of
Long:strings intoExample:across a broad set of Cobra command definitions. - Kept non-example explanatory text (e.g., “Repository modes”, “The command will:”) in
Long:where appropriate. - Updated help-text consistency tests to assert against
cmd.Exampleinstead ofcmd.Long.
Show a summary per file
| File | Description |
|---|---|
| pkg/cli/view_command.go | Moves view examples into Example:. |
| pkg/cli/validate_command.go | Moves validate examples into Example: while keeping WorkflowIDExplanation in Long:. |
| pkg/cli/upgrade_command.go | Moves upgrade examples into Example:. |
| pkg/cli/upgrade_command_test.go | Updates assertions to check cmd.Example. |
| pkg/cli/update_command.go | Moves update examples into Example:. |
| pkg/cli/trial_command.go | Keeps repository-mode prose in Long: and moves runnable examples into Example:. |
| pkg/cli/tokens_bootstrap.go | Moves secrets bootstrap examples into Example:. |
| pkg/cli/status.go | Moves status examples into Example:. |
| pkg/cli/secrets_command.go | Moves secrets examples into Example:. |
| pkg/cli/secret_set_command.go | Moves secrets set examples into Example:. |
| pkg/cli/project_command.go | Moves project and project new examples into Example:. |
| pkg/cli/pr_command.go | Moves pr / pr transfer examples into Example:. |
| pkg/cli/outcomes_history.go | Moves outcomes history examples into Example:. |
| pkg/cli/outcomes_command.go | Moves outcomes examples into Example:. |
| pkg/cli/mcp.go | Moves mcp examples into Example:. |
| pkg/cli/mcp_server_command.go | Moves mcp-server examples into Example:. |
| pkg/cli/mcp_server_command_test.go | Updates assertions to check cmd.Example. |
| pkg/cli/mcp_list.go | Moves mcp list examples into Example:. |
| pkg/cli/mcp_list_tools.go | Moves mcp list-tools examples into Example:. |
| pkg/cli/mcp_inspect.go | Moves mcp inspect examples into Example:. |
| pkg/cli/mcp_add.go | Moves mcp add examples into Example:. |
| pkg/cli/logs_command.go | Moves extensive logs examples into Example:. |
| pkg/cli/logs_command_test.go | Splits expectations: Long section checks vs Example content checks. |
| pkg/cli/list_workflows_command.go | Moves list examples into Example:. |
| pkg/cli/lint_command.go | Moves lint examples into Example:. |
| pkg/cli/init_command.go | Moves init examples into Example:. |
| pkg/cli/health_command.go | Moves health examples into Example:. |
| pkg/cli/hash_command.go | Moves hash-frontmatter examples into Example:. |
| pkg/cli/forecast_command.go | Moves forecast examples into Example:. |
| pkg/cli/fix_command.go | Moves fix examples into Example:. |
| pkg/cli/experiments_command.go | Moves experiments examples into Example: for command + subcommands. |
| pkg/cli/domains_command.go | Moves domains examples into Example:. |
| pkg/cli/deploy_command.go | Moves deploy examples into Example:. |
| pkg/cli/completion_command.go | Moves completion usage examples into Example: for command + subcommands. |
| pkg/cli/completion_command_test.go | Updates assertions to check cmd.Example. |
| pkg/cli/cli_consistency_help_test.go | Updates consistency expectations to reflect Example: usage. |
| pkg/cli/checks_command.go | Moves checks examples into Example:. |
| pkg/cli/audit.go | Moves audit examples into Example:. |
| pkg/cli/audit_diff_command.go | Moves audit diff examples into Example:. |
| pkg/cli/add_wizard_command.go | Moves add-wizard examples into Example:. |
| pkg/cli/add_command.go | Moves add examples into Example:. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 41/41 changed files
- Comments generated: 0
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. |
|
🧪 Test Quality Sentinel completed test quality analysis. |
|
🧠 Matt Pocock Skills Reviewer failed during the skills-based review. |
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (148 new lines in 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. ❓ Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does. Adopting cobra's native 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
🧪 Test Quality Sentinel Report
📊 Metrics & Test Classification (6 tests analyzed)
Test Classification Details
Language SupportTests analyzed:
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 70/100. Test quality is acceptable — 0% of modified tests are implementation tests (threshold: 30%). All 6 test modifications are design tests verifying observable cobra command fields. No coding-guideline violations detected.
There was a problem hiding this comment.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · 600.7 AIC · ⌖ 13.8 AIC · ⊞ 27.8K
| ` + string(constants.CLIExtensionPrefix) + ` add ./my-workflow.md # Add local workflow | ||
| ` + string(constants.CLIExtensionPrefix) + ` add ./*.md # Add all local workflows | ||
| ` + string(constants.CLIExtensionPrefix) + ` add githubnext/agentics/ci-doctor --dir .github/workflows/shared # Add to .github/workflows/shared/ | ||
| `, |
There was a problem hiding this comment.
[/zoom-out] Trailing \n inconsistency: this Example field ends with a blank line before the closing backtick, but the majority of the 36 migrated commands do not. Seven files share this pattern (add_command.go, add_wizard_command.go, mcp_add.go, mcp_inspect.go, mcp_list.go, mcp_list_tools.go, trial_command.go). Cobra normalises trailing whitespace in help output so this is invisible at runtime, but the source inconsistency will make future diffs noisier.
💡 Suggested fix
Remove the blank line before the closing backtick in all seven files:
// Before
Example: ` gh aw add ...
gh aw add ./*.md
`,
// After
Example: ` gh aw add ...
gh aw add ./*.md`,This makes the style consistent with the other 29 migrated commands.
| assert.Contains(t, preReleasesFlag.Usage, "Include pre-release versions", "--pre-releases description should mention pre-release upgrades") | ||
| assert.Contains(t, preReleasesFlag.Usage, "installed by exact tag", "--pre-releases description should explain prerelease pinning") | ||
| assert.Contains(t, cmd.Long, "stable releases are the default", "help text should distinguish stable releases from prereleases") | ||
| assert.Contains(t, cmd.Example, "stable releases are the default", "help text should distinguish stable releases from prereleases") |
There was a problem hiding this comment.
[/tdd] This assertion now pins a behavioural claim ("stable releases are the default") to the Example: field rather than Long:. The text passes because it happens to appear as an inline comment in an example line, but the test intent — verifying that the help text explains the stable/pre-release distinction as a concept — is no longer matched to the right field.
💡 Suggested improvement
Add a dedicated sentence to Long: in upgrade_command.go that explicitly mentions the stable/prerelease default, then assert cmd.Long for that prose and keep a separate cmd.Example assertion for the example line:
// upgrade_command.go – add to Long:
assert.Contains(t, cmd.Long, "stable releases are the default", ...)
// and keep the existing example test separate
assert.Contains(t, cmd.Example, "--pre-releases", ...)This way the test message "help text should distinguish stable releases from prereleases" accurately reflects what is being verified.
| cmd := NewTrialCommand(func(string) error { return nil }) | ||
|
|
||
| assert.Contains(t, cmd.Long, "Examples:", "trial long help should use the standard examples heading") | ||
| assert.NotEmpty(t, cmd.Example, "trial command should use cobra's Example field for examples") |
There was a problem hiding this comment.
[/tdd] assert.NotEmpty checks only the trial command; a new command added without an Example: field would silently regress. Since this PR just established the contract across 36 commands, now is a natural time to add a table-driven guard.
💡 Suggested extension
func TestAllCommandsHaveExampleField(t *testing.T) {
root := NewRootCommand()
for _, cmd := range root.Commands() {
if cmd.Runnable() {
assert.NotEmpty(t, cmd.Example, "%s should define cobra Example: field", cmd.Name())
}
for _, sub := range cmd.Commands() {
if sub.Runnable() {
assert.NotEmpty(t, sub.Example, "%s %s should define cobra Example: field", cmd.Name(), sub.Name())
}
}
}
}This acts as a lint guard preventing future regressions without any per-command boilerplate.
| `, | ||
| Args: func(cmd *cobra.Command, args []string) error { | ||
| if len(args) < 1 { | ||
| return fmt.Errorf("missing workflow specification\n\nUsage:\n %s <workflow>...\n\nExamples:\n %[1]s githubnext/agentics/daily-repo-status Add from repository\n %[1]s ./my-workflow.md Add local workflow\n\nRun '%[1]s --help' for more information", cmd.CommandPath()) |
There was a problem hiding this comment.
[/zoom-out] The Args validation error string still contains "Examples:" (plural, old style) as an embedded heading. This is unrelated to cobra.Command.Example: but is a user-facing string that now looks inconsistent post-migration. The same pattern exists in deploy_command.go (line 83).
💡 Optional cleanup
Update the error format string to use "Example:" (singular, matching cobra convention):
return fmt.Errorf(
"missing workflow specification\n\nUsage:\n %s <workflow>...\n\nExample:\n ...",
cmd.CommandPath(),
)This is non-blocking but keeps user-visible text consistent.
None of the ~36 cobra command definitions in
pkg/cli/used theExample:field — all commands with usage examples embedded them as hand-written prose insideLong:. This breakscobra/doc.GenMarkdownTree()docs generation and makes examples untestable.Changes
Command files (36 files)
Moved
Examples:sections fromLong:to the cobraExample:field across all command files. Two source patterns handled:Long:string: split at\n\nExamples:\nboundaryWorkflowIDExplanationconcatenation: cleaned up empty-string artifact after splitBefore / After:
Secondary fixes (8 files)
8 files had non-example prose (e.g.,
Workflow specifications:,Repository modes:,The command will:) that ended up inExample:due to being interleaved after theExamples:section in the originalLong:. Moved back toLong:where they belong:add_command.go,add_wizard_command.go,mcp_add.go,mcp_inspect.go,mcp_list.go,mcp_list_tools.go,trial_command.go,pr_command.go.Test updates (5 files)
Tests asserting
cmd.Longcontained example strings updated to checkcmd.Exampleinstead:cli_consistency_help_test.go,completion_command_test.go,logs_command_test.go,mcp_server_command_test.go,upgrade_command_test.go.