(commands: Array<{ command: CommandConstructor, path: string[] }>)
| 167 | // derive from the same full-depth `collectCommands` walk and the canonical |
| 168 | // space-joined command path. |
| 169 | export function renderCommandRows(commands: Array<{ command: CommandConstructor, path: string[] }>): string { |
| 170 | const rows = commands.map(({ command, path }) => ({ |
| 171 | label: path.join(' '), |
| 172 | desc: command.description ?? '', |
| 173 | group: path[0] ?? '', |
| 174 | })) |
| 175 | |
| 176 | const width = rows.reduce((max, r) => Math.max(max, r.label.length), 0) + 2 |
| 177 | const lines: string[] = [] |
| 178 | let prevGroup: string | undefined |
| 179 | |
| 180 | for (const r of rows) { |
| 181 | if (prevGroup !== undefined && r.group !== prevGroup) |
| 182 | lines.push('') |
| 183 | |
| 184 | prevGroup = r.group |
| 185 | lines.push(r.desc ? ` ${r.label.padEnd(width)}${r.desc}` : ` ${r.label}`) |
| 186 | } |
| 187 | |
| 188 | return lines.join('\n') |
| 189 | } |
| 190 | |
| 191 | // Renders a command list (a namespace subtree for `<group> --help`) in the |
| 192 | // requested format: structured formats serialize per-command descriptors — the |
no test coverage detected