UNPKG

@jovotech/cli

Version:

Jovo Command Line Interface (Beta)

60 lines 2.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandHelp = void 0; const cli_core_1 = require("@jovotech/cli-core"); const command_1 = __importDefault(require("@oclif/help/lib/command")); const list_1 = require("@oclif/help/lib/list"); class CommandHelp extends command_1.default { /** * Mimicks the functionality of super.flags(), but customizes some minor * things such as output of flag parameters */ flags(flags) { const output = list_1.renderList(flags.map((flag) => { var _a, _b; const label = []; if (!flag.helpLabel) { if (flag.char) { label.push(`-${flag.char}, `); } if (flag.name) { if (flag.type === 'boolean' && flag.allowNo) { label.push(`--[no-]${flag.name.trim()}`); } else { label.push(`--${flag.name.trim()}`); } } } else { label.push(flag.helpLabel); } // Append options if defined if (flag.type === 'option') { if (flag.options) { label.push(cli_core_1.chalk.dim(`={${flag.options.join('|')}}`)); } else { label.push(cli_core_1.chalk.dim(`={${((_a = flag.helpLabel) === null || _a === void 0 ? void 0 : _a.trim()) || flag.name.trim()}}`)); } } // Add description to flag const description = []; if (flag.required) { description.push('(required) '); } description.push(flag.description || ''); if (flag.type === 'option' && ((_b = flag.default) === null || _b === void 0 ? void 0 : _b.length)) { description.push(`\n[default: ${flag.default}]`); } const s = [label.join(''), cli_core_1.chalk.dim(description.join(''))]; return s; }), { stripAnsi: this.opts.stripAnsi, maxWidth: this.opts.maxWidth - 2 }); return [cli_core_1.chalk.bold('FLAGS'), cli_core_1.Log.info(output, { dry: true, indent: 2, newLine: false })].join('\n'); } } exports.CommandHelp = CommandHelp; //# sourceMappingURL=CommandHelp.js.map