| 5 | import { CLIExtension } from './cli.extension'; |
| 6 | |
| 7 | export class LegacyCommandAdapter implements Command { |
| 8 | alias: string; |
| 9 | name: string; |
| 10 | description: string; |
| 11 | options: CommandOptions; |
| 12 | shortDescription: string; |
| 13 | group: string; |
| 14 | loader?: boolean; |
| 15 | commands: Command[]; |
| 16 | private?: boolean; |
| 17 | migration?: boolean; |
| 18 | internal?: boolean; |
| 19 | _packageManagerArgs?: string[]; |
| 20 | constructor(private cmd: LegacyCommand, cliExtension: CLIExtension) { |
| 21 | this.name = cmd.name; |
| 22 | this.description = cmd.description; |
| 23 | this.options = cmd.opts || []; |
| 24 | this.alias = cmd.alias; |
| 25 | const commandID = getID(cmd.name); |
| 26 | const { summery, group } = findLegacyDetails(commandID, cliExtension); |
| 27 | this.shortDescription = summery; |
| 28 | this.group = group; |
| 29 | this.loader = cmd.loader; |
| 30 | this.private = cmd.private; |
| 31 | this.migration = cmd.migration; |
| 32 | this.internal = cmd.internal; |
| 33 | this.commands = (cmd.commands || []).map(sub => new LegacyCommandAdapter(sub, cliExtension)); |
| 34 | } |
| 35 | |
| 36 | private async action(params: any, options: { [key: string]: any }): Promise<ActionResult> { |
| 37 | const res = await this.cmd.action(params, options, this._packageManagerArgs); |
| 38 | let data = res; |
| 39 | let code = 0; |
| 40 | if (res && res.__code !== undefined) { |
| 41 | data = res.data; |
| 42 | code = res.__code; |
| 43 | } |
| 44 | const report = this.cmd.report(data, params, options); |
| 45 | return { |
| 46 | code, |
| 47 | report |
| 48 | }; |
| 49 | } |
| 50 | |
| 51 | async report(params: any, options: { [key: string]: any }): Promise<{ data: string; code: number }> { |
| 52 | const actionResult = await this.action(params, options); |
| 53 | return { data: actionResult.report, code: actionResult.code }; |
| 54 | } |
| 55 | |
| 56 | async json(params: any, options: { [key: string]: any }): Promise<GenericObject> { |
| 57 | const actionResult = await this.action(params, options); |
| 58 | return { |
| 59 | data: JSON.parse(actionResult.report), |
| 60 | code: actionResult.code |
| 61 | }; |
| 62 | } |
| 63 | } |
| 64 |
nothing calls this directly
no outgoing calls
no test coverage detected