"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ListApplicationsCommand = void 0;
const os_1 = require("os");
const util = require("util");
const _ = require("lodash");
const yok_1 = require("../../yok");
class ListApplicationsCommand {
    constructor($devicesService, $logger, $options) {
        this.$devicesService = $devicesService;
        this.$logger = $logger;
        this.$options = $options;
        this.allowedParameters = [];
    }
    async execute(args) {
        await this.$devicesService.initialize({
            deviceId: this.$options.device,
            skipInferPlatform: true,
        });
        const output = [];
        const action = async (device) => {
            const applications = await device.applicationManager.getInstalledApplications();
            output.push(util.format("%s=====Installed applications on device with UDID '%s' are:", os_1.EOL, device.deviceInfo.identifier));
            _.each(applications, (applicationId) => output.push(applicationId));
        };
        await this.$devicesService.execute(action);
        this.$logger.info(output.join(os_1.EOL));
    }
}
exports.ListApplicationsCommand = ListApplicationsCommand;
yok_1.injector.registerCommand(["device|list-applications", "devices|list-applications"], ListApplicationsCommand);
