1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.CLIError = exports.addOclifExitCode = void 0;
|
5 | const config_1 = require("../config");
|
6 | function addOclifExitCode(error, options) {
|
7 | if (!('oclif' in error)) {
|
8 | error.oclif = {};
|
9 | }
|
10 | error.oclif.exit = (options === null || options === void 0 ? void 0 : options.exit) === undefined ? 2 : options.exit;
|
11 | return error;
|
12 | }
|
13 | exports.addOclifExitCode = addOclifExitCode;
|
14 | class CLIError extends Error {
|
15 | constructor(error, options = {}) {
|
16 | super(error instanceof Error ? error.message : error);
|
17 | this.oclif = {};
|
18 | addOclifExitCode(this, options);
|
19 | this.code = options.code;
|
20 | }
|
21 | get stack() {
|
22 | const clean = require('clean-stack');
|
23 | return clean(super.stack, { pretty: true });
|
24 | }
|
25 | |
26 |
|
27 |
|
28 |
|
29 | render() {
|
30 | if (config_1.config.debug) {
|
31 | return this.stack;
|
32 | }
|
33 | const wrap = require('wrap-ansi');
|
34 | const indent = require('indent-string');
|
35 | let output = `${this.name}: ${this.message}`;
|
36 |
|
37 | output = wrap(output, require('../screen').errtermwidth - 6, { trim: false, hard: true });
|
38 | output = indent(output, 3);
|
39 | output = indent(output, 1, { indent: this.bang, includeEmptyLines: true });
|
40 | output = indent(output, 1);
|
41 | return output;
|
42 | }
|
43 | get bang() {
|
44 | let red = ((s) => s);
|
45 | try {
|
46 | red = require('chalk').red;
|
47 | }
|
48 | catch (_a) { }
|
49 | return red(process.platform === 'win32' ? '»' : '›');
|
50 | }
|
51 | }
|
52 | exports.CLIError = CLIError;
|
53 | (function (CLIError) {
|
54 | class Warn extends CLIError {
|
55 | constructor(err) {
|
56 | super(err instanceof Error ? err.message : err);
|
57 | this.name = 'Warning';
|
58 | }
|
59 | get bang() {
|
60 | let yellow = ((s) => s);
|
61 | try {
|
62 | yellow = require('chalk').yellow;
|
63 | }
|
64 | catch (_a) { }
|
65 | return yellow(process.platform === 'win32' ? '»' : '›');
|
66 | }
|
67 | }
|
68 | CLIError.Warn = Warn;
|
69 | })(CLIError = exports.CLIError || (exports.CLIError = {}));
|