(ctor: CommandConstructor, path: string)
| 101 | } |
| 102 | |
| 103 | function formatHelpText(ctor: CommandConstructor, path: string): string { |
| 104 | const lines: string[] = [] |
| 105 | |
| 106 | if (ctor.description) |
| 107 | lines.push(ctor.description, '') |
| 108 | |
| 109 | lines.push('USAGE', ` $ ${BIN} ${path}${ctor.args && Object.keys(ctor.args).length > 0 ? ' [ARGS]' : ''}${ctor.flags && Object.keys(ctor.flags).length > 0 ? ' [FLAGS]' : ''}`, '') |
| 110 | |
| 111 | if (ctor.args && Object.keys(ctor.args).length > 0) { |
| 112 | lines.push('ARGUMENTS') |
| 113 | |
| 114 | for (const [name, def] of Object.entries(ctor.args)) { |
| 115 | const required = def.required ? ' (required)' : '' |
| 116 | lines.push(` ${name}${required} ${def.description}`) |
| 117 | } |
| 118 | |
| 119 | lines.push('') |
| 120 | } |
| 121 | |
| 122 | if (ctor.flags && Object.keys(ctor.flags).length > 0) { |
| 123 | lines.push('FLAGS') |
| 124 | |
| 125 | for (const [name, def] of Object.entries(ctor.flags)) { |
| 126 | lines.push(` ${flagLabel(name, def)} ${def.description}${flagDefault(def)}`) |
| 127 | } |
| 128 | |
| 129 | lines.push('') |
| 130 | } |
| 131 | |
| 132 | if (ctor.examples && ctor.examples.length > 0) { |
| 133 | lines.push('EXAMPLES') |
| 134 | |
| 135 | for (const ex of renderExamples(ctor)) { |
| 136 | lines.push(` $ ${ex}`) |
| 137 | } |
| 138 | |
| 139 | lines.push('') |
| 140 | } |
| 141 | |
| 142 | const guide = agentGuideOf(ctor) |
| 143 | |
| 144 | if (guide.length > 0) |
| 145 | lines.push(guide) |
| 146 | |
| 147 | return lines.join('\n') |
| 148 | } |
| 149 | |
| 150 | export function formatHelp(ctor: CommandConstructor, path: string, format = ''): string { |
| 151 | if (isStructured(format)) |
no test coverage detected