download: Implement factory/OTA and multi-build support

This commit is contained in:
Danny Lin 2021-12-17 14:21:02 -08:00
parent cd86042e75
commit 14a4a57e5e

View file

@ -1,7 +1,13 @@
import { Command, flags } from '@oclif/command' import { Command, flags } from '@oclif/command'
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import chalk from 'chalk' import chalk from 'chalk'
import { downloadFile } from '../images/download' import { downloadFile, ImageType } from '../images/download'
const IMAGE_TYPE_MAP: { [type: string]: ImageType } = {
'factory': ImageType.Factory,
'ota': ImageType.Ota,
'vendor': ImageType.Vendor,
}
export default class Download extends Command { export default class Download extends Command {
static description = 'download device factory images, OTAs, and/or vendor packages' static description = 'download device factory images, OTAs, and/or vendor packages'
@ -9,7 +15,7 @@ export default class Download extends Command {
static flags = { static flags = {
help: flags.help({char: 'h'}), help: flags.help({char: 'h'}),
type: flags.string({char: 't', options: ['factory', 'ota', 'vendor'], description: 'type(s) of images to download', default: 'factory', multiple: true}), type: flags.string({char: 't', options: ['factory', 'ota', 'vendor'], description: 'type(s) of images to download', default: 'factory', multiple: true}),
buildId: flags.string({char: 'b', description: 'build ID/number of the image(s) to download', required: true}), buildId: flags.string({char: 'b', description: 'build ID(s) of the images to download', required: true, multiple: true}),
device: flags.string({char: 'd', description: 'device(s) to download images for', required: true, multiple: true}), device: flags.string({char: 'd', description: 'device(s) to download images for', required: true, multiple: true}),
} }
@ -22,15 +28,20 @@ export default class Download extends Command {
await fs.mkdir(out, { recursive: true }) await fs.mkdir(out, { recursive: true })
let buildId = flags.buildId.toUpperCase() for (let device of flags.device) {
this.log(chalk.greenBright(`${device}`))
for (let type of flags.type) { for (let type of flags.type) {
let prettyType = type == 'ota' ? 'OTA' : type.charAt(0).toUpperCase() + type.slice(1) let typeEnum = IMAGE_TYPE_MAP[type]
this.log(chalk.bold(chalk.blueBright(`${prettyType} - ${buildId}`))) if (typeEnum == undefined) {
throw new Error(`Unknown type ${type}`)
}
let prettyType = type == 'ota' ? 'OTA' : type.charAt(0).toUpperCase() + type.slice(1)
for (let device of flags.device) { for (let buildId of flags.buildId) {
this.log(chalk.greenBright(` ${device}`)) this.log(chalk.bold(chalk.blueBright(` ${prettyType} - ${buildId.toUpperCase()}`)))
await downloadFile(type, buildId, device, out) await downloadFile(typeEnum, buildId, device, out)
}
} }
} }
} }