UNPKG

keystone-seeder

Version:
58 lines (57 loc) 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BoxedHelp = void 0; const commander_1 = require("commander"); class BoxedHelp extends commander_1.Help { constructor() { super(...arguments); this.boxTop = '╭'; this.boxBottom = '╰'; this.boxVertical = '│'; this.boxHorizontal = '─'; this.boxTopRight = '╮'; this.boxBottomRight = '╯'; } createBox(content, title) { const lines = content.split('\n').filter(line => line.trim()); const maxLength = Math.max(...lines.map(line => line.length)); let result = ''; // Create top border with optional title if (title) { result += `${this.boxTop}${this.boxHorizontal} ${title} ${this.boxHorizontal.repeat(maxLength - title.length - 1)}${this.boxTopRight}\n`; } else { result += `${this.boxTop}${this.boxHorizontal.repeat(maxLength + 2)}${this.boxTopRight}\n`; } // Add content lines lines.forEach(line => { const padding = ' '.repeat(maxLength - line.length); result += `${this.boxVertical} ${line}${padding} ${this.boxVertical}\n`; }); // Add bottom border result += `${this.boxBottom}${this.boxHorizontal.repeat(maxLength + 2)}${this.boxBottomRight}\n`; return result; } formatHelp(cmd, helper) { const term = helper.commandTerm(cmd); const description = helper.commandDescription(cmd); const args = helper.visibleArguments(cmd).map((arg) => { return `${arg.name} ${arg.description}`; }); const options = helper.visibleOptions(cmd).map((option) => { return `${option.flags} ${option.description}`; }); let sections = []; // Command name and description if (term) sections.push(this.createBox(`${term}\n${description}`, 'Command')); // Arguments if (args.length) sections.push(this.createBox(args.join('\n'), 'Arguments')); // Options if (options.length) sections.push(this.createBox(options.join('\n'), 'Options')); return sections.join('\n'); } } exports.BoxedHelp = BoxedHelp;