UNPKG

actionhero

Version:

The reusable, scalable, and quick node.js API server for stateless and stateful applications

47 lines (46 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CLI = void 0; /** * An Actionhero CLI Command. * For inputs, you can provide Options (--thing=stuff) with the "Inputs" object, or define Arguments in the name of the command (`greet [name]`) */ 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](); } } } /** * An optional method to append additional information to the --help response for this CLI command */ help() { } getDefaults() { return { name: null, description: this.name, example: "", inputs: {}, initialize: true, start: false, }; } 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;