@nu-art/commando
Version:
74 lines (73 loc) • 2.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseCommando = void 0;
const ts_common_1 = require("@nu-art/ts-common");
const CommandBuilder_1 = require("./CommandBuilder");
const class_merger_1 = require("./class-merger");
class BaseCommando {
/**
* Creates a new instance of BaseCommando merged with the provided plugins.
* @param {Constructor<any>[]} plugins - The plugins to merge with BaseCommando.
* @returns The Super type merged of BaseCommando and all the plugins provided new instance of BaseCommando merged with the plugins.
*/
static _create(...plugins) {
const _commando = (0, class_merger_1.CreateMergedInstance)(BaseCommando, ...plugins);
const commando = _commando;
// @ts-ignore
commando.builder = new CommandBuilder_1.CommandBuilder();
return commando;
}
/**
* Constructs a BaseCommando instance.
*/
constructor() {
this._debug = false;
this.builder = new CommandBuilder_1.CommandBuilder();
}
/**
* Toggles or sets the debug mode.
* @param {boolean} [debug] - If provided, sets the debug mode to this value. Otherwise, toggles the current debug mode.
* @returns {boolean} - The current state of debug mode.
*/
debug(debug) {
this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
return this;
}
/**
* Appends a command to the command list.
* @param {string} command - The command to append.
* @returns {this} - The BaseCommando instance for method chaining.
*/
append(command) {
this.builder.append(command);
return this;
}
/**
* Increases the current indentation level by one.
* @returns {this} - The BaseCommando instance for method chaining.
*/
indentIn() {
this.builder.indentIn();
return this;
}
/**
* Decreases the current indentation level by one.
* @returns {this} - The BaseCommando instance for method chaining.
*/
indentOut() {
this.builder.indentOut();
return this;
}
/**
* Appends an empty line to the script for readability.
* @returns {this} - The BaseCommando instance for method chaining.
*/
emptyLine() {
this.builder.emptyLine();
return this;
}
async execute(callback) {
throw new ts_common_1.ImplementationMissingException('need to override this method in your class');
}
}
exports.BaseCommando = BaseCommando;