balena-cli
Version:
The official balena Command Line Interface
64 lines (62 loc) • 2.47 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const cf = require("../../utils/common-flags");
const lazy_1 = require("../../utils/lazy");
const core_1 = require("@oclif/core");
class FleetListCmd extends core_1.Command {
async run() {
const { flags: options } = await this.parse(FleetListCmd);
const balena = (0, lazy_1.getBalenaSdk)();
const pineOptions = {
$select: ['id', 'app_name', 'slug'],
$expand: {
is_for__device_type: { $select: 'slug' },
owns__device: { $select: 'is_online' },
},
};
const applications = (await balena.models.application.getAllDirectlyAccessible(pineOptions));
applications.forEach((application) => {
var _a, _b, _c;
application.device_count = (_b = (_a = application.owns__device) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
application.online_devices =
((_c = application.owns__device) === null || _c === void 0 ? void 0 : _c.filter((d) => d.is_online).length) || 0;
application.device_type = application.is_for__device_type[0].slug;
});
const applicationsToDisplay = applications.map((application) => ({
id: application.id,
app_name: application.app_name,
slug: application.slug,
device_type: application.device_type,
online_devices: application.online_devices,
device_count: application.device_count,
}));
if (options.json) {
console.log(JSON.stringify(applicationsToDisplay, null, 4));
return;
}
console.log((0, lazy_1.getVisuals)().table.horizontal(applicationsToDisplay, [
'id',
'app_name => NAME',
'slug',
'device_type',
'device_count',
'online_devices',
]));
}
}
FleetListCmd.aliases = ['fleets'];
FleetListCmd.deprecateAliases = true;
FleetListCmd.description = (0, lazy_1.stripIndent) `
List all fleets.
List all your balena fleets.
For detailed information on a particular fleet, use
\`balena fleet <fleet>\`
`;
FleetListCmd.examples = ['$ balena fleet list'];
FleetListCmd.flags = {
json: cf.json,
};
FleetListCmd.authenticated = true;
FleetListCmd.primary = true;
exports.default = FleetListCmd;
//# sourceMappingURL=list.js.map
;