UNPKG

@adpt/cli

Version:
91 lines 3.48 kB
"use strict"; /* * Copyright 2018-2019 Unbounded Systems, LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const path_1 = require("path"); const util = tslib_1.__importStar(require("util")); const base_1 = require("../../base"); const proj_1 = require("../../proj"); const dynamic_task_mgr_1 = require("../../ui/dynamic_task_mgr"); function formatDeployments(info) { return info.map((i) => i.deployID).join("\n"); } function getErrorMsg(e) { if ("message" in e) return e.message; return util.inspect(e); } class ListCommand extends base_1.DeployBase { async run() { const ctx = this.ctx; if (ctx == null) { throw new Error(`Internal error: ctx cannot be null`); } this.tasks.add({ title: "Checking for project-level adapt module", skip: () => { if (this.ctx.projectFile === undefined) { this.adapt = require("@adpt/core"); return "Project root file not found, using internal adapt module"; } }, task: async (_ctx, task) => { if (this.ctx.projectFile === undefined) { throw new Error(`Internal error: projectFile should not be undefined`); } try { this.adapt = await proj_1.projectAdaptModule(path_1.dirname(this.ctx.projectFile)); } catch (e) { const msg = getErrorMsg(e); task.skip(`${msg}, using internal adapt module`); this.adapt = require("@adpt/core"); } } }); const logger = ctx.logger.createChild("list"); const loggerId = logger.from; dynamic_task_mgr_1.addDynamicTask(this.tasks, ctx.logger.from, ctx.client, { id: loggerId, title: "Listing Deployments", adoptable: true, initiate: () => this.adapt.listDeployments({ adaptUrl: ctx.adaptUrl, client: ctx.client, logger, loggerId, }), onCompleteRoot: async (_ctx, _task, err, prom) => { const info = await dynamic_task_mgr_1.waitForInitiate(err, prom); if (!this.isApiSuccess(info, { action: "list" })) return; this.appendOutput(formatDeployments(info.deployments)); } }); await this.tasks.run(); } } ListCommand.description = "List active Adapt deployments"; ListCommand.aliases = ["list"]; ListCommand.examples = [ `List all deployments from the server $ adapt deploy:list`, ]; ListCommand.flags = Object.assign({}, base_1.DeployBase.flags); ListCommand.args = []; exports.default = ListCommand; //# sourceMappingURL=list.js.map