UNPKG

branch-remover

Version:

A small application for quickly removing unnecessary branches from GitHub.

72 lines 2.93 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.helpCommand = void 0; const chalk_1 = __importDefault(require("chalk")); const cli_table_1 = __importDefault(require("cli-table")); const GetParams_1 = require("./GetParams"); const Schema_1 = require("./Schema"); const helpCommand = () => { var _a; // TODO: PackageInfo service const { name: packageName, version: packageVersion, } = require('../../package.json'); const additionalInfo = new Array(); const getRow = (x) => { var _a, _b, _c, _d; return { [`--${x.name}`]: [ (_b = (_a = x.aliases) === null || _a === void 0 ? void 0 : _a.map((x) => `--${x}`).join('\n')) !== null && _b !== void 0 ? _b : chalk_1.default.italic('n/a'), (_d = (_c = x.description) === null || _c === void 0 ? void 0 : _c.join('\n')) !== null && _d !== void 0 ? _d : chalk_1.default.italic('n/a'), ], }; }; let rows = Schema_1.schema.map(getRow); let param = null; if (typeof GetParams_1.params.help === 'string') { const findName = GetParams_1.params.help.toString().trim(); param = Schema_1.schema.find((x) => { var _a; return x.name === findName || ((_a = x.aliases) === null || _a === void 0 ? void 0 : _a.includes(findName)); }); if (param) { rows = [getRow(param)]; if ((_a = param.examples) === null || _a === void 0 ? void 0 : _a.length) { additionalInfo.push('', 'Examples:', '─────────', ...param.examples.map((x) => { const result = new Array(); if (x.title) { result.push(chalk_1.default.italic(x.title)); } result.push(`> ${x.example}`); if (x.notes) { result.push(''); result.push(x.notes); result.push(''); } return result.join('\n') + '\n'; })); } } else { console.error(`Unknown parameter name "${findName}".`); } } const table = new cli_table_1.default({ head: [ 'Parameter', 'Aliases', 'Description', ], }); table.push(...rows); console.log(`${packageName} v${packageVersion}`, param ? `/ ${param.name}` : ''); console.log(table.toString()); if (additionalInfo === null || additionalInfo === void 0 ? void 0 : additionalInfo.length) { console.log(additionalInfo.join('\n')); } process.exit(); }; exports.helpCommand = helpCommand; //# sourceMappingURL=HelpCommand.js.map