UNPKG

balena-cli

Version:

The official balena Command Line Interface

79 lines (76 loc) 3.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const _ = require("lodash"); const lazy_1 = require("../../utils/lazy"); class DeviceTypeListCmd extends core_1.Command { async run() { const { flags: options } = await this.parse(DeviceTypeListCmd); const pineOptions = { $select: ['slug', 'name'], $expand: { is_of__cpu_architecture: { $select: 'slug' }, device_type_alias: { $select: 'is_referenced_by__alias', $orderby: { is_referenced_by__alias: 'asc' }, }, }, }; const dts = (options.all ? await (0, lazy_1.getBalenaSdk)().models.deviceType.getAll(pineOptions) : await (0, lazy_1.getBalenaSdk)().models.deviceType.getAllSupported(pineOptions)); let deviceTypes = dts.map((dt) => { var _a; const aliases = dt.device_type_alias .map((dta) => dta.is_referenced_by__alias) .filter((alias) => alias !== dt.slug); return { slug: dt.slug, aliases: options.json ? aliases : [aliases.join(', ')], arch: ((_a = dt.is_of__cpu_architecture[0]) === null || _a === void 0 ? void 0 : _a.slug) || 'n/a', name: dt.name || 'N/A', }; }); const fields = ['slug', 'aliases', 'arch', 'name']; deviceTypes = _.sortBy(deviceTypes, fields); if (options.json) { console.log(JSON.stringify(deviceTypes, null, 4)); } else { const visuals = (0, lazy_1.getVisuals)(); const output = await visuals.table.horizontal(deviceTypes, fields); console.log(output); } } } DeviceTypeListCmd.aliases = ['devices supported']; DeviceTypeListCmd.deprecateAliases = true; DeviceTypeListCmd.description = (0, lazy_1.stripIndent) ` List the device types supported by balena (like 'raspberrypi3' or 'intel-nuc'). List the device types supported by balena (like 'raspberrypi3' or 'intel-nuc'). By default, only actively supported device types are listed. The --all option can be used to list all device types, including those that are no longer supported by balena. The --json option is recommended when scripting the output of this command, because the JSON format is less likely to change and it better represents data types like lists and empty strings (for example, the ALIASES column contains a list of zero or more values). The 'jq' utility may be helpful in shell scripts (https://stedolan.github.io/jq/manual/). `; DeviceTypeListCmd.examples = [ '$ balena device-type list', '$ balena device-type list --all', '$ balena device-type list --json', ]; DeviceTypeListCmd.flags = { json: core_1.Flags.boolean({ char: 'j', description: 'produce JSON output instead of tabular output', }), all: core_1.Flags.boolean({ description: 'include device types no longer supported by balena', default: false, }), }; exports.default = DeviceTypeListCmd; //# sourceMappingURL=list.js.map