UNPKG

cli-engine

Version:
73 lines (59 loc) 1.81 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _cliEngineCommand = require('cli-engine-command'); var _cliEngineCommand2 = _interopRequireDefault(_cliEngineCommand); var _screen = require('cli-engine-command/lib/screen'); var _dispatcher = require('../dispatcher'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // import {compare} from '../util' function trimToMaxLeft(n) { let max = parseInt(_screen.stdtermwidth * 0.6); return n > max ? max : n; } function trimCmd(s, max) { if (s.length <= max) return s; return `${s.slice(0, max - 1)}\u2026`; } function renderList(items) { const S = require('string'); const max = require('lodash.maxby'); let maxLeftLength = trimToMaxLeft(max(items, '[0].length')[0].length + 1); return items.map(i => { let left = ` ${i[0]}`; let right = i[1]; if (!right) return left; left = `${S(trimCmd(left, maxLeftLength)).padRight(maxLeftLength)}`; right = linewrap(maxLeftLength + 2, right); return `${left} ${right}`; }).join('\n'); } function linewrap(length, s) { const linewrap = require('@heroku/linewrap'); return linewrap(length, _screen.stdtermwidth, { skipScheme: 'ansi-color' })(s).trim(); } class Help extends _cliEngineCommand2.default { async run() { await this.topics(); } async topics() { let dispatcher = new _dispatcher.Dispatcher(this.config); let topics = await dispatcher.listTopics(); // let topics = [ // [ // 'topica', // 'desc' // ] // ] topics.sort(); this.out.log(renderList(topics.map(t => [t, 'desc']))); this.out.log(); } } exports.default = Help; Help.topic = 'help'; Help.description = 'display help'; Help.variableArgs = true;