1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", { value: true });
|
4 | exports.warn = exports.error = exports.exit = void 0;
|
5 | var handle_1 = require("./handle");
|
6 | Object.defineProperty(exports, "handle", { enumerable: true, get: function () { return handle_1.handle; } });
|
7 | var exit_1 = require("./errors/exit");
|
8 | Object.defineProperty(exports, "ExitError", { enumerable: true, get: function () { return exit_1.ExitError; } });
|
9 | var cli_1 = require("./errors/cli");
|
10 | Object.defineProperty(exports, "CLIError", { enumerable: true, get: function () { return cli_1.CLIError; } });
|
11 | var logger_1 = require("./logger");
|
12 | Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_1.Logger; } });
|
13 | var config_1 = require("./config");
|
14 | Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_1.config; } });
|
15 | const config_2 = require("./config");
|
16 | const cli_2 = require("./errors/cli");
|
17 | const exit_2 = require("./errors/exit");
|
18 | const pretty_print_1 = require("./errors/pretty-print");
|
19 | function exit(code = 0) {
|
20 | throw new exit_2.ExitError(code);
|
21 | }
|
22 | exports.exit = exit;
|
23 | function error(input, options = {}) {
|
24 | var _a;
|
25 | let err;
|
26 | if (typeof input === 'string') {
|
27 | err = new cli_2.CLIError(input, options);
|
28 | }
|
29 | else if (input instanceof Error) {
|
30 | err = cli_2.addOclifExitCode(input, options);
|
31 | }
|
32 | else {
|
33 | throw new TypeError('first argument must be a string or instance of Error');
|
34 | }
|
35 | err = pretty_print_1.applyPrettyPrintOptions(err, options);
|
36 | if (options.exit === false) {
|
37 | const message = pretty_print_1.default(err);
|
38 | console.error(message);
|
39 | if (config_2.config.errorLogger)
|
40 | config_2.config.errorLogger.log((_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : '');
|
41 | }
|
42 | else
|
43 | throw err;
|
44 | }
|
45 | exports.error = error;
|
46 | function warn(input) {
|
47 | var _a;
|
48 | let err;
|
49 | if (typeof input === 'string') {
|
50 | err = new cli_2.CLIError.Warn(input);
|
51 | }
|
52 | else if (input instanceof Error) {
|
53 | err = cli_2.addOclifExitCode(input);
|
54 | }
|
55 | else {
|
56 | throw new TypeError('first argument must be a string or instance of Error');
|
57 | }
|
58 | const message = pretty_print_1.default(err);
|
59 | console.error(message);
|
60 | if (config_2.config.errorLogger)
|
61 | config_2.config.errorLogger.log((_a = err === null || err === void 0 ? void 0 : err.stack) !== null && _a !== void 0 ? _a : '');
|
62 | }
|
63 | exports.warn = warn;
|