@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
59 lines • 2.16 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const schema_1 = require("@sprucelabs/schema");
const SpruceError_1 = __importDefault(require("../../../errors/SpruceError"));
const AbstractAction_1 = __importDefault(require("../../AbstractAction"));
const optionsSchema = (0, schema_1.buildSchema)({
id: 'unregisterSkill',
description: 'Unregister a skill from your account.',
fields: {},
});
class UnregisterSkillAction extends AbstractAction_1.default {
optionsSchema = optionsSchema;
commandAliases = ['unregister.skill'];
invocationMessage = 'Unregistering skill... 🔧';
skills;
constructor(options) {
super(options);
this.skills = this.Store('skill');
}
async execute() {
const response = {};
const skills = await this.skills.fetchMySkills();
if (skills.length > 0) {
const skillId = await this.ui.prompt({
type: 'select',
isRequired: true,
options: {
choices: skills.map((skill) => this.skillToChoices(skill)),
},
});
const match = skills.find((s) => s.id === skillId);
const confirm = await this.ui.confirm(`Are you sure you want to unregister the skill "${match?.name}"?`);
if (confirm) {
await this.skills.unregisterSkill(skillId);
response.summaryLines = [`Unregistered ${match?.name}`];
}
else {
response.summaryLines = ['Unregister cancelled.'];
}
}
else {
response.errors = [
new SpruceError_1.default({ code: 'NO_SKILLS_REGISTERED' }),
];
}
return response;
}
skillToChoices(skill) {
return {
value: skill.id,
label: `${skill.slug}: ${skill.name}`,
};
}
}
exports.default = UnregisterSkillAction;
//# sourceMappingURL=UnregisterSkillAction.js.map