download: Implement factory/OTA and multi-build support
This commit is contained in:
parent
cd86042e75
commit
14a4a57e5e
1 changed files with 20 additions and 9 deletions
|
@ -1,7 +1,13 @@
|
|||
import { Command, flags } from '@oclif/command'
|
||||
import { promises as fs } from 'fs'
|
||||
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 {
|
||||
static description = 'download device factory images, OTAs, and/or vendor packages'
|
||||
|
@ -9,7 +15,7 @@ export default class Download extends Command {
|
|||
static flags = {
|
||||
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}),
|
||||
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}),
|
||||
}
|
||||
|
||||
|
@ -22,15 +28,20 @@ export default class Download extends Command {
|
|||
|
||||
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) {
|
||||
let prettyType = type == 'ota' ? 'OTA' : type.charAt(0).toUpperCase() + type.slice(1)
|
||||
this.log(chalk.bold(chalk.blueBright(`${prettyType} - ${buildId}`)))
|
||||
for (let type of flags.type) {
|
||||
let typeEnum = IMAGE_TYPE_MAP[type]
|
||||
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) {
|
||||
this.log(chalk.greenBright(` ${device}`))
|
||||
await downloadFile(type, buildId, device, out)
|
||||
for (let buildId of flags.buildId) {
|
||||
this.log(chalk.bold(chalk.blueBright(` ${prettyType} - ${buildId.toUpperCase()}`)))
|
||||
await downloadFile(typeEnum, buildId, device, out)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue