balena-cli
Version:
The official balena Command Line Interface
94 lines (91 loc) • 3.52 kB
JavaScript
;
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, _e, _f;
return ({
...device,
dashboard_url: balena.models.device.getDashboardUrl(device.uuid),
fleet: (_c = (_b = (_a = device.belongs_to__application) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.slug) !== null && _c !== void 0 ? _c : null,
uuid: options.json ? device.uuid : device.uuid.slice(0, 7),
device_type: (_f = (_e = (_d = device.is_of__device_type) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.slug) !== null && _f !== void 0 ? _f : 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));
return JSON.stringify(mapped, null, 4);
}
console.log((0, lazy_1.getVisuals)().table.horizontal(devices.map((dev) => (0, helpers_1.defaultValues)(dev, 'N/a')), fields));
}
}
DeviceListCmd.enableJsonFlag = 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')}
`;
DeviceListCmd.examples = [
'$ balena device list',
'$ balena device list --fleet MyFleet',
'$ balena device list -f myorg/myfleet',
];
DeviceListCmd.flags = {
fleet: cf.fleet,
};
DeviceListCmd.primary = true;
DeviceListCmd.authenticated = true;
exports.default = DeviceListCmd;
//# sourceMappingURL=list.js.map