UNPKG

@auttam/easycli

Version:

A quick and easy way of creating cli for your npm package.

27 lines (26 loc) 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.required = void 0; const program_config_1 = require("../config/program-config"); const settings_1 = require("../settings"); const config_error_1 = require("../errors/config-error"); const command_config_1 = require("../config/command-config"); function required(target, propertyKey, parameterIndex) { if (!settings_1.SettingStore.enableCommands) return; if (!target || typeof propertyKey != 'string' || typeof target[propertyKey] != 'function') { throw new config_error_1.ConfigurationError("There was some problem applying @required decorator"); } var config = program_config_1.ProgramConfiguration.injectConfiguration(target); config.decoratorsEnabled = true; var command = config.commands.get(propertyKey); if (!command) { command = new command_config_1.Command({ method: propertyKey }); command.params.initByMethod(target[propertyKey]); } command.params.toArray()[parameterIndex].required = true; config.commands.addByCommand(command); } exports.required = required;