ValidateExamples is the contractual mechanism by which cmdhelp v0.1 prevents documentation drift (spec §6, §11 Q5). For every example in every command of `doc`: 1. Tokenize the `cmd` string with a shell-aware splitter. 2. Resolve the non-flag tokens against `root`'s live cobra command tree. Failure
(doc *Document, root *cobra.Command)
| 26 | // Callers must pass `root` so flag-tree walks can include persistent |
| 27 | // flags from the binary root. |
| 28 | func ValidateExamples(doc *Document, root *cobra.Command) []string { |
| 29 | if doc == nil || root == nil { |
| 30 | return nil |
| 31 | } |
| 32 | var findings []string |
| 33 | |
| 34 | for path, cmd := range doc.Commands { |
| 35 | for i, ex := range cmd.Examples { |
| 36 | if ferrs := validateExample(path, i, ex, doc, root); len(ferrs) > 0 { |
| 37 | findings = append(findings, ferrs...) |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | return findings |
| 42 | } |
| 43 | |
| 44 | func validateExample(path string, idx int, ex Example, doc *Document, root *cobra.Command) []string { |
| 45 | tokens, err := shellSplit(ex.Cmd) |