UNPKG

takin

Version:

Front end engineering base toolchain and scaffold

59 lines 1.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); class Option { constructor(rawName, description, config) { this.rawName = rawName; this.description = description; this.config = Object.assign({}, config); // You may use cli.option('--env.* [value]', 'desc') to denote a dot-nested option rawName = rawName.replace(/\.\*/g, ''); this.negated = false; this.names = this.parse(rawName); this.sortNamesAndSetActualName(); if (this.negated && this.config.default == null) { this.config.default = true; } if (rawName.includes('<')) { this.required = true; } else if (rawName.includes('[')) { this.required = false; } else { // No arg needed, it's boolean flag this.isBoolean = true; } } parse(rawName) { return (0, utils_1.removeBrackets)(rawName) .split(',') .map((v) => { let name = v.trim().replace(/^-{1,2}/, ''); if (name.startsWith('no-')) { this.negated = true; name = name.replace(/^no-/, ''); } return (0, utils_1.camelcaseOptionName)(name); }); } /** * 为 option 设置别名 */ alias(rawName) { const names = this.parse(rawName); for (const name of names) { if (this.names.includes(name)) continue; this.names.push(name); } this.sortNamesAndSetActualName(); } sortNamesAndSetActualName() { this.names = (this.names || []).sort((a, b) => a.length > b.length ? 1 : -1); // Sort names // Use the longest name (last one) as actual option name this.name = this.names[this.names.length - 1]; } } exports.default = Option; //# sourceMappingURL=option.js.map