UNPKG

balena-cli

Version:

The official balena Command Line Interface

101 lines (97 loc) 3.69 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const cf = require("../../utils/common-flags"); const helpers_1 = require("../../utils/helpers"); const lazy_1 = require("../../utils/lazy"); const messages_1 = require("../../utils/messages"); const devicesSelectFields = { $select: [ 'id', 'uuid', 'device_name', 'status', 'is_online', 'supervisor_version', 'os_version', ], }; class DeviceListCmd extends core_1.Command { async run() { const { flags: options } = await this.parse(DeviceListCmd); const balena = (0, lazy_1.getBalenaSdk)(); const devicesOptions = { ...devicesSelectFields, ...helpers_1.expandForAppName, $orderby: { device_name: 'asc' }, }; const devices = (await (async () => { if (options.fleet != null) { const { getApplication } = await Promise.resolve().then(() => require('../../utils/sdk')); const application = await getApplication(balena, options.fleet, { $select: 'slug', $expand: { owns__device: devicesOptions, }, }); return application.owns__device; } return await balena.pine.get({ resource: 'device', options: devicesOptions, }); })()).map((device) => { var _a, _b, _c, _d; return ({ ...device, dashboard_url: balena.models.device.getDashboardUrl(device.uuid), fleet: ((_b = (_a = device.belongs_to__application) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.slug) || null, uuid: options.json ? device.uuid : device.uuid.slice(0, 7), device_type: ((_d = (_c = device.is_of__device_type) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.slug) || null, }); }); const fields = [ 'id', 'uuid', 'device_name', 'device_type', 'fleet', 'status', 'is_online', 'supervisor_version', 'os_version', 'dashboard_url', ]; if (options.json) { const { pickAndRename } = await Promise.resolve().then(() => require('../../utils/helpers')); const mapped = devices.map((device) => pickAndRename(device, fields)); console.log(JSON.stringify(mapped, null, 4)); } else { const _ = await Promise.resolve().then(() => require('lodash')); console.log((0, lazy_1.getVisuals)().table.horizontal(devices.map((dev) => _.mapValues(dev, (val) => val !== null && val !== void 0 ? val : 'N/a')), fields)); } } } DeviceListCmd.aliases = ['devices']; DeviceListCmd.deprecateAliases = true; DeviceListCmd.description = (0, lazy_1.stripIndent) ` List all devices. List all of your devices. Devices can be filtered by fleet with the \`--fleet\` option. ${messages_1.applicationIdInfo.split('\n').join('\n\t\t')} ${messages_1.jsonInfo.split('\n').join('\n\t\t')} `; DeviceListCmd.examples = [ '$ balena device list', '$ balena device list --fleet MyFleet', '$ balena device list -f myorg/myfleet', ]; DeviceListCmd.flags = { fleet: cf.fleet, json: cf.json, }; DeviceListCmd.primary = true; DeviceListCmd.authenticated = true; exports.default = DeviceListCmd; //# sourceMappingURL=list.js.map