UNPKG

actionhero

Version:

actionhero.js is a multi-transport API Server with integrated cluster capabilities and delayed tasks

40 lines (39 loc) 1.19 kB
"use strict"; /** * Create a new Actionhero CLI Command. The required properties of an CLI command. These can be defined statically (this.name) or as methods which return a value. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.CLI = void 0; class CLI { constructor() { const defaults = this.getDefaults(); for (const key in defaults) { if (!this[key]) { this[key] = defaults[key]; } if (typeof this[key] === "function") { this[key] = this[key](); } } } getDefaults() { return { name: null, description: this.name, example: "", inputs: {}, }; } validate() { if (!this.name) { throw new Error("name is required for this cli command"); } if (!this.description) { throw new Error(`description is required for the cli commend \`${this.name}\``); } if (!this.run || typeof this.run !== "function") { throw new Error(`cli command \`${this.name}\` has no run method`); } } } exports.CLI = CLI;