1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const chalk_1 = require("chalk");
|
4 | const indent = require("indent-string");
|
5 | const stripAnsi = require("strip-ansi");
|
6 | const util_1 = require("./util");
|
7 | const wrap = require('wrap-ansi');
|
8 | const { bold, } = chalk_1.default;
|
9 | class RootHelp {
|
10 | constructor(config, opts) {
|
11 | this.config = config;
|
12 | this.opts = opts;
|
13 | this.render = util_1.template(this);
|
14 | }
|
15 | root() {
|
16 | let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
17 | description = this.render(description);
|
18 | description = description.split('\n')[0];
|
19 | let output = util_1.compact([
|
20 | description,
|
21 | this.version(),
|
22 | this.usage(),
|
23 | this.description(),
|
24 | ]).join('\n\n');
|
25 | if (this.opts.stripAnsi)
|
26 | output = stripAnsi(output);
|
27 | return output;
|
28 | }
|
29 | usage() {
|
30 | return [
|
31 | bold('USAGE'),
|
32 | indent(wrap(`$ ${this.config.bin} [COMMAND]`, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
33 | ].join('\n');
|
34 | }
|
35 | description() {
|
36 | let description = this.config.pjson.oclif.description || this.config.pjson.description || '';
|
37 | description = this.render(description);
|
38 | description = description.split('\n').slice(1).join('\n');
|
39 | if (!description)
|
40 | return;
|
41 | return [
|
42 | bold('DESCRIPTION'),
|
43 | indent(wrap(description, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
44 | ].join('\n');
|
45 | }
|
46 | version() {
|
47 | return [
|
48 | bold('VERSION'),
|
49 | indent(wrap(this.config.userAgent, this.opts.maxWidth - 2, { trim: false, hard: true }), 2),
|
50 | ].join('\n');
|
51 | }
|
52 | }
|
53 | exports.default = RootHelp;
|