UNPKG

@acot/cli

Version:
40 lines (39 loc) 1.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildUsage = void 0; const strip_ansi_1 = __importDefault(require("strip-ansi")); const chalk_1 = __importDefault(require("chalk")); const length = (s) => (0, strip_ansi_1.default)(s).length; const buildUsage = (sections) => { const maxContentSize = sections.reduce((max, section) => { if (!Array.isArray(section.content)) { return max; } return section.content.reduce((acc, cur) => { return Math.max(acc, length(cur.name)); }, max); }, 0); return sections .map((section) => { const wrapContent = (s) => (section.raw === true ? s : ` ${s}`); const line = []; if (section.header != null) { line.push(chalk_1.default.bold(section.header)); } if (typeof section.content === 'string') { line.push(wrapContent(section.content)); } else { section.content.forEach((content) => { const padding = ' '.repeat(maxContentSize - length(content.name)); line.push(wrapContent(`${content.name}${padding} ${content.summary}`)); }); } return line.join('\n'); }) .join('\n\n'); }; exports.buildUsage = buildUsage;