UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

62 lines 2.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const installSkillAtOrganizationOptions_schema_1 = __importDefault(require("./../../../.spruce/schemas/spruceCli/v2020_07_22/installSkillAtOrganizationOptions.schema")); const SpruceError_1 = __importDefault(require("../../../errors/SpruceError")); const AbstractAction_1 = __importDefault(require("../../AbstractAction")); class InstallAction extends AbstractAction_1.default { commandAliases = ['install.skill']; optionsSchema = installSkillAtOrganizationOptions_schema_1.default; invocationMessage = 'Installing skill at org... 🏙'; async execute(options) { try { const skill = await this.Store('skill').loadCurrentSkill(); if (!skill.id) { throw new SpruceError_1.default({ code: 'SKILL_NOT_REGISTERED' }); } let { organizationId } = this.validateAndNormalizeOptions(options); if (!organizationId) { const orgs = await this.Store('organization').fetchMyOrganizations(); if (orgs.length === 0) { throw new SpruceError_1.default({ code: 'NO_ORGANIZATIONS_FOUND', }); } if (orgs.length === 1) { const confirm = await this.ui.confirm(`You ready to install your skill at ${orgs[0].name}?`); if (!confirm) { return {}; } organizationId = orgs[0].id; } else { const choices = orgs.map((o) => ({ value: o.id, label: o.name, })); organizationId = (await this.ui.prompt({ type: 'select', label: 'Which organization should we install your skill to?', isRequired: true, options: { choices, }, })); } } await this.Store('organization').installSkillAtOrganization(skill.id, organizationId); return { summaryLines: ['Skill installed!'], }; } catch (err) { return { errors: [err], }; } } } exports.default = InstallAction; //# sourceMappingURL=InstallAction.js.map