From e1d69888dd4a75970124efe7b0d488723d89d1fd Mon Sep 17 00:00:00 2001 From: Dmitry Muhomor Date: Wed, 23 Aug 2023 16:27:27 +0300 Subject: [PATCH] add fetch-build-index command --- src/commands/fetch-build-index.ts | 33 +++++++++++++++++++++++++++++++ src/util/yaml.ts | 11 +++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/commands/fetch-build-index.ts create mode 100644 src/util/yaml.ts diff --git a/src/commands/fetch-build-index.ts b/src/commands/fetch-build-index.ts new file mode 100644 index 0000000..887a6e3 --- /dev/null +++ b/src/commands/fetch-build-index.ts @@ -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) + } +} diff --git a/src/util/yaml.ts b/src/util/yaml.ts new file mode 100644 index 0000000..fce2012 --- /dev/null +++ b/src/util/yaml.ts @@ -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 + } +}