"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.memoizedWarn = exports.warn = void 0;
const write_1 = __importDefault(require("../cli-ux/write"));
const config_1 = require("./config");
const cli_1 = require("./errors/cli");
const pretty_print_1 = __importDefault(require("./errors/pretty-print"));
function warn(input) {
    let err;
    if (typeof input === 'string') {
        err = new cli_1.CLIError.Warn(input);
    }
    else if (input instanceof Error) {
        err = (0, cli_1.addOclifExitCode)(input);
    }
    else {
        throw new TypeError('first argument must be a string or instance of Error');
    }
    const message = (0, pretty_print_1.default)(err);
    if (message)
        write_1.default.stderr(message + '\n');
    if (config_1.config.errorLogger)
        config_1.config.errorLogger.log(err?.stack ?? '');
}
exports.warn = warn;
const WARNINGS = new Set();
function memoizedWarn(input) {
    if (!WARNINGS.has(input))
        warn(input);
    WARNINGS.add(input);
}
exports.memoizedWarn = memoizedWarn;
exports.default = warn;
