| 237 | } |
| 238 | |
| 239 | private printCommandHelp(cmd: Command, out: NodeJS.WriteStream, region: Region = 'global'): void { |
| 240 | const b = (s: string) => this.bold(s, out); |
| 241 | const a = (s: string) => this.accent(s, out); |
| 242 | const d = (s: string) => this.dim(s, out); |
| 243 | |
| 244 | out.write(`\n${cmd.description}\n`); |
| 245 | if (cmd.usage) out.write(`${b('Usage:')} ${cmd.usage}\n`); |
| 246 | if (cmd.options && cmd.options.length > 0) { |
| 247 | const maxLen = Math.max(...cmd.options.map(o => o.flag.length)); |
| 248 | out.write(`\n${b('Options:')}\n`); |
| 249 | for (const opt of cmd.options) { |
| 250 | out.write(` ${a(opt.flag.padEnd(maxLen + 2))} ${d(opt.description)}\n`); |
| 251 | } |
| 252 | } |
| 253 | if (cmd.examples && cmd.examples.length > 0) { |
| 254 | out.write(`\n${b('Examples:')}\n`); |
| 255 | for (const ex of cmd.examples) { |
| 256 | out.write(` ${d(ex)}\n`); |
| 257 | } |
| 258 | } |
| 259 | if (cmd.apiDocs) { |
| 260 | out.write(`\n${b('API Reference:')} ${d(DOCS_HOSTS[region] + cmd.apiDocs)}\n`); |
| 261 | } |
| 262 | out.write(`\n${d('Global flags (--api-key, --output, --quiet, etc.) are always available.')}\n`); |
| 263 | out.write(`${d("Run")} mmx --help ${d('for the full list.')}\n`); |
| 264 | } |
| 265 | |
| 266 | private printChildren(node: CommandNode, prefix: string, out: NodeJS.WriteStream): void { |
| 267 | const entries: Array<{ fullName: string; description: string }> = []; |