(op: Operation)
| 118 | } |
| 119 | |
| 120 | export function commandHelp(op: Operation): string { |
| 121 | const required = new Set(op.input.required ?? []); |
| 122 | const lines = [`decap ${op.cli!.command.join(' ')}`, '', op.summary, '']; |
| 123 | const fields = Object.entries(op.input.properties); |
| 124 | if (fields.length > 0) { |
| 125 | lines.push('Flags:'); |
| 126 | const width = Math.max(...fields.map(([field]) => flagName(field).length)) + 2; |
| 127 | for (const [field, prop] of fields) { |
| 128 | const choices = |
| 129 | prop.type === 'string' && prop.enum |
| 130 | ? ` (${prop.enum.join(', ')})` |
| 131 | : prop.type === 'object' |
| 132 | ? ' (JSON)' |
| 133 | : ''; |
| 134 | lines.push( |
| 135 | ` --${flagName(field).padEnd(width)}${required.has(field) ? 'required. ' : ''}${ |
| 136 | prop.description ?? '' |
| 137 | }${choices}`, |
| 138 | ); |
| 139 | } |
| 140 | lines.push(''); |
| 141 | } |
| 142 | lines.push( |
| 143 | `Needs ${op.scope === 'admin' ? 'admin scope (decap login --admin)' : 'a signed-in token'}.`, |
| 144 | ); |
| 145 | lines.push('Add --json for machine-readable output.'); |
| 146 | return lines.join('\n'); |
| 147 | } |
| 148 | |
| 149 | /** One line per command, for the main help. */ |
| 150 | export function commandList(): string { |
no test coverage detected