(cmd *cobra.Command)
| 150 | } |
| 151 | |
| 152 | func buildCommand(cmd *cobra.Command) Command { |
| 153 | out := Command{ |
| 154 | Summary: firstLine(cmd.Short), |
| 155 | } |
| 156 | |
| 157 | // Long-form description: only emit if it adds something beyond Short. |
| 158 | if longTrimmed := strings.TrimSpace(cmd.Long); longTrimmed != "" && longTrimmed != cmd.Short && firstLine(longTrimmed) != cmd.Short { |
| 159 | out.Description = longTrimmed |
| 160 | } |
| 161 | |
| 162 | out.Args = parseArgs(cmd) |
| 163 | if flags := collectFlags(cmd.LocalFlags()); len(flags) > 0 { |
| 164 | out.Flags = flags |
| 165 | } |
| 166 | |
| 167 | // Examples come from cobra's dedicated Example field when set. |
| 168 | // Many CLIs (pad included, historically) embed an "Examples:" |
| 169 | // section in Long instead. Fall back to parsing that block so |
| 170 | // existing commands populate examples in cmdhelp output without a |
| 171 | // Long → Example migration. Long stays the canonical Long; the |
| 172 | // extracted examples become the Examples field, leaving room for |
| 173 | // commands to migrate to cobra's structured field on their own |
| 174 | // schedule. |
| 175 | out.Examples = parseExamples(cmd.Example) |
| 176 | if len(out.Examples) == 0 { |
| 177 | out.Examples = parseExamplesFromLong(cmd.Long) |
| 178 | } |
| 179 | |
| 180 | return out |
| 181 | } |
| 182 | |
| 183 | // examplesHeaderRE matches a stand-alone "Examples:" or "Example:" |
| 184 | // section header in a cobra Long string. Anchored to a line on its own |
no test coverage detected