"use strict";
// *****************************************************************************
// Copyright (C) 2023 STMicroelectronics and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
var PluginMgmtCliContribution_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PluginMgmtCliContribution = void 0;
const tslib_1 = require("tslib");
const inversify_1 = require("@theia/core/shared/inversify");
const hosted_plugin_deployer_handler_1 = require("../../hosted/node/hosted-plugin-deployer-handler");
const common_1 = require("../../common");
let PluginMgmtCliContribution = PluginMgmtCliContribution_1 = class PluginMgmtCliContribution {
    configure(conf) {
        conf.command([PluginMgmtCliContribution_1.LIST_PLUGINS, 'list-extensions'], 'List the installed plugins', yargs => yargs.option(PluginMgmtCliContribution_1.SHOW_VERSIONS, {
            description: 'List the versions of the installed plugins',
            type: 'boolean',
            default: false,
        }).option(PluginMgmtCliContribution_1.SHOW_BUILTINS, {
            description: 'List the built-in plugins',
            type: 'boolean',
            default: false,
        }), async (yargs) => {
            const showVersions = yargs[PluginMgmtCliContribution_1.SHOW_VERSIONS];
            const deployedIds = await this.deployerHandler.getDeployedBackendPlugins();
            const pluginType = yargs[PluginMgmtCliContribution_1.SHOW_BUILTINS] ? common_1.PluginType.System : common_1.PluginType.User;
            process.stdout.write('installed plugins:\n');
            deployedIds.filter(plugin => plugin.type === pluginType).forEach(plugin => {
                if (showVersions) {
                    process.stdout.write(`${plugin.metadata.model.id}@${plugin.metadata.model.version}\n`);
                }
                else {
                    process.stdout.write(`${plugin.metadata.model.id}\n`);
                }
            });
        });
    }
    setArguments(args) {
    }
};
PluginMgmtCliContribution.LIST_PLUGINS = 'list-plugins';
PluginMgmtCliContribution.SHOW_VERSIONS = '--show-versions';
PluginMgmtCliContribution.SHOW_BUILTINS = '--show-builtins';
(0, tslib_1.__decorate)([
    (0, inversify_1.inject)(hosted_plugin_deployer_handler_1.HostedPluginDeployerHandler),
    (0, tslib_1.__metadata)("design:type", hosted_plugin_deployer_handler_1.HostedPluginDeployerHandler)
], PluginMgmtCliContribution.prototype, "deployerHandler", void 0);
PluginMgmtCliContribution = PluginMgmtCliContribution_1 = (0, tslib_1.__decorate)([
    (0, inversify_1.injectable)()
], PluginMgmtCliContribution);
exports.PluginMgmtCliContribution = PluginMgmtCliContribution;
//# sourceMappingURL=plugin-mgmt-cli-contribution.js.map