vtex
Version:
The platform for e-commerce apps
45 lines (44 loc) • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.renderCommands = exports.getHelpSubject = void 0;
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const indent_string_1 = tslib_1.__importDefault(require("indent-string"));
const api_1 = require("../../api");
const list_1 = require("@oclif/plugin-help/lib/list");
const root_1 = tslib_1.__importDefault(require("@oclif/plugin-help/lib/root"));
const constants_1 = require("./constants");
function getHelpSubject(args) {
for (const arg of args) {
if (arg === '--' || arg.startsWith('-'))
return;
if (['help', '--help', '-h'].includes(arg))
continue;
return arg;
}
}
exports.getHelpSubject = getHelpSubject;
function renderCommand(commands, ctx) {
return list_1.renderList(commands.map(c => [chalk_1.default.hex(api_1.COLORS.PINK)(c.name), c.description && ctx.render(c.description.split('\n')[0])]), {
spacer: '\n',
stripAnsi: ctx.opts.stripAnsi,
maxWidth: ctx.opts.maxWidth - 2,
});
}
function renderCommands(commandsId, groups, ctx) {
const body = [];
const commandsGroupLength = Object.keys(commandsId).length;
const help = new root_1.default(ctx.config, ctx.opts);
body.push(help.root());
body.push(' ');
for (let [key, value] of Object.entries(commandsId)) {
key = key !== constants_1.OTHER_GROUP_ID ? key : (commandsGroupLength - 1).toString();
if (groups[key].length > 0) {
body.push(chalk_1.default.bold(value));
body.push(indent_string_1.default(renderCommand(groups[key], ctx), 2));
body.push(' ');
}
}
return body.join('\n');
}
exports.renderCommands = renderCommands;