add fetch-build-index command
This commit is contained in:
parent
83ac2dba38
commit
e1d69888dd
2 changed files with 44 additions and 0 deletions
33
src/commands/fetch-build-index.ts
Normal file
33
src/commands/fetch-build-index.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { Command, flags } from '@oclif/command'
|
||||||
|
import { YAMLMap } from 'yaml/types'
|
||||||
|
|
||||||
|
import { DEVICE_CONFIG_FLAGS, loadDeviceConfigs } from '../config/device'
|
||||||
|
import { fetchBetaBuildIndex, fetchBuildIndex } from '../images/build-index'
|
||||||
|
import { yamlStringifyNoFold } from '../util/yaml'
|
||||||
|
|
||||||
|
export default class FetchBuildIndex extends Command {
|
||||||
|
description = 'fetch main or beta build index and print it out as YAML'
|
||||||
|
|
||||||
|
static flags = {
|
||||||
|
...DEVICE_CONFIG_FLAGS,
|
||||||
|
beta: flags.string({
|
||||||
|
char: 'b',
|
||||||
|
description: 'Fetch index of beta builds for the specified major OS version (e.g. -b 14)',
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
|
async run() {
|
||||||
|
let { flags } = this.parse(FetchBuildIndex)
|
||||||
|
let devices = await loadDeviceConfigs(flags.devices)
|
||||||
|
|
||||||
|
let index: YAMLMap
|
||||||
|
if (flags.beta === undefined) {
|
||||||
|
index = await fetchBuildIndex(devices)
|
||||||
|
} else {
|
||||||
|
index = await fetchBetaBuildIndex(devices, flags.beta)
|
||||||
|
}
|
||||||
|
|
||||||
|
let yaml = yamlStringifyNoFold(index)
|
||||||
|
this.log(yaml)
|
||||||
|
}
|
||||||
|
}
|
11
src/util/yaml.ts
Normal file
11
src/util/yaml.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import YAML, { Options } from 'yaml'
|
||||||
|
|
||||||
|
export function yamlStringifyNoFold(value: any, options?: Options) {
|
||||||
|
let orig = YAML.scalarOptions.str.fold.lineWidth
|
||||||
|
YAML.scalarOptions.str.fold.lineWidth = 0
|
||||||
|
try {
|
||||||
|
return YAML.stringify(value, options)
|
||||||
|
} finally {
|
||||||
|
YAML.scalarOptions.str.fold.lineWidth = orig
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue