<commit_before>const Command = Jymfony.Component.Console.Command.Command;
const ConsoleEvents = Jymfony.Component.Console.ConsoleEvents;
const CommandNotFoundException = Jymfony.Component.Console.Exception.CommandNotFoundException;
const ExceptionInterface = Jymfony.Component.Console.Exception.ExceptionInterface;
const ArgvInput = Jymfony.Component.Console.Input.ArgvInput;
const ArrayInput = Jymfony.Component.Console.Input.ArrayInput;
const InputArgument = Jymfony.Component.Console.Input.InputArgument;
const InputDefinition = Jymfony.Component.Console.Input.InputDefinition;
const InputOption = Jymfony.Component.Console.Input.InputOption;
const StreamableInputInterface = Jymfony.Component.Console.Input.StreamableInputInterface;
const ConsoleOutput = Jymfony.Component.Console.Output.ConsoleOutput;
const ConsoleOutputInterface = Jymfony.Component.Console.Output.ConsoleOutputInterface;
const OutputInterface = Jymfony.Component.Console.Output.OutputInterface;
const OutputFormatter = Jymfony.Component.Console.Formatter.OutputFormatter;
const Terminal = Jymfony.Component.Console.Terminal;

const util = require('util');

/**
 * @memberOf Jymfony.Component.Console
 */
class Application {
    __construct(name = 'UNKNOWN', version = 'UNKNOWN') {
        this._name = name;
        this._version = version;
        this._eventDispatcher = undefined;
        this._defaultCommand = 'list';
        this._definition = this._getDefaultInputDefinition();
        this._commands = {};
        this._terminal = new Terminal();
        this._catchExceptions = true;
        this._autoExit = true;

        for (let command of this._getDefaultCommands()) {
            this.add(command);
        }
    }

    /**
     * Sets the event dispatcher.
     *
     * @param {Jymfony.Component.EventDispatcher.EventDispatcher} dispatcher
     */
    set dispatcher(dispatcher) {
        this._eventDispatcher = dispatcher;
    }

    /**
     * Set an input definition to be used with this application.
     *
     * @param {Jymfony.Component.Console.Input.InputDefinition} definition The input definition
     */
    set definition(definition) {
        this._definition = definition;
    }

    /**
     * Gets the InputDefinition related to this Application.
     *
     * @returns {Jymfony.Component.Console.Input.InputDefinition} The InputDefinition instance
     */
    get definition() {
        return this._definition;
    }

    /**
     * Gets the help message.
     *
     * @returns {string} A help message
     */
    get help() {
        return this.getLongVersion();
    }

    /**
     * Sets the default Command name.
     *
     * @param {string} commandName The Command name
     */
    set defaultCommand(commandName) {
        this._defaultCommand = commandName;
    }

    /**
     * Sets whether to catch exceptions while running or not.
     *
     * @param {boolean} catchExceptions
     */
    set catchExceptions(catchExceptions) {
        this._catchExceptions = catchExceptions;
    }

    /**
     * Sets if application should automatically terminate when run
     * has been completed.
     *
     * @param {boolean} autoExit
     */
    set autoExit(autoExit) {
        this._autoExit = autoExit;
    }

    /**
     * Run the application
     *
     * @param {Jymfony.Component.Console.Input.InputInterface} input
     * @param {Jymfony.Component.Console.Output.OutputInterface} output
     *
     * @returns {Promise} Promise executing the application
     */
    run(input = new ArgvInput(), output = new ConsoleOutput()) {
        this._configureIO(input, output);

        let promise = __jymfony.Async.run(this._doRun(input, output));

        if (this._catchExceptions) {
            promise = promise
                .catch((exception) => {
                    if (output instanceof ConsoleOutputInterface) {
                        this._renderException(exception, output.errorOutput);
                    } else {
                        this._renderException(exception, output);
                    }

                    let exitCode = exception.code || 1;
                    if (! isNumber(exitCode)) {
                        exitCode = 1;
                    }

                    if (255 < exitCode) {
                        exitCode = 255;
                    }

                    return exitCode;
                })
                .then(exitCode => {
                    if (this._autoExit) {
                        process.exit(exitCode);
                    }

                    return process.exitCode = exitCode;
                })
            ;
        }

        return promise;
    }

    /**
     * Returns the long version of the application.
     *
     * @returns {string} The long application version
     */
    getLongVersion() {
        if ('UNKNOWN' !== this.name) {
            if ('UNKNOWN' !== this.version) {
                return util.format('%s <info>%s</info>', this.name, this.version);
            }

            return this.name;
        }

        return 'Console Tool';
    }

    /**
     * Registers a new command.<commit_msg>[Console] defer process exit to next tick<commit_after>const Command = Jymfony.Component.Console.Command.Command;
const ConsoleEvents = Jymfony.Component.Console.ConsoleEvents;
const CommandNotFoundException = Jymfony.Component.Console.Exception.CommandNotFoundException;
const ExceptionInterface = Jymfony.Component.Console.Exception.ExceptionInterface;
const ArgvInput = Jymfony.Component.Console.Input.ArgvInput;
const ArrayInput = Jymfony.Component.Console.Input.ArrayInput;
const InputArgument = Jymfony.Component.Console.Input.InputArgument;
const InputDefinition = Jymfony.Component.Console.Input.InputDefinition;
const InputOption = Jymfony.Component.Console.Input.InputOption;
const StreamableInputInterface = Jymfony.Component.Console.Input.StreamableInputInterface;
const ConsoleOutput = Jymfony.Component.Console.Output.ConsoleOutput;
const ConsoleOutputInterface = Jymfony.Component.Console.Output.ConsoleOutputInterface;
const OutputInterface = Jymfony.Component.Console.Output.OutputInterface;
const OutputFormatter = Jymfony.Component.Console.Formatter.OutputFormatter;
const Terminal = Jymfony.Component.Console.Terminal;

const util = require('util');

/**
 * @memberOf Jymfony.Component.Console
 */
class Application {
    __construct(name = 'UNKNOWN', version = 'UNKNOWN') {
        this._name = name;
        this._version = version;
        this._eventDispatcher = undefined;
        this._defaultCommand = 'list';
        this._definition = this._getDefaultInputDefinition();
        this._commands = {};
        this._terminal = new Terminal();
        this._catchExceptions = true;
        this._autoExit = true;

        for (let command of this._getDefaultCommands()) {
            this.add(command);
        }
    }

    /**
     * Sets the event dispatcher.
     *
     * @param {Jymfony.Component.EventDispatcher.EventDispatcher} dispatcher
     */
    set dispatcher(dispatcher) {
        this._eventDispatcher = dispatcher;
    }

    /**
     * Set an input definition to be used with this application.
     *
     * @param {Jymfony.Component.Console.Input.InputDefinition} definition The input definition
     */
    set definition(definition) {
        this._definition = definition;
    }

    /**
     * Gets the InputDefinition related to this Application.
     *
     * @returns {Jymfony.Component.Console.Input.InputDefinition} The InputDefinition instance
     */
    get definition() {
        return this._definition;
    }

    /**
     * Gets the help message.
     *
     * @returns {string} A help message
     */
    get help() {
        return this.getLongVersion();
    }

    /**
     * Sets the default Command name.
     *
     * @param {string} commandName The Command name
     */
    set defaultCommand(commandName) {
        this._defaultCommand = commandName;
    }

    /**
     * Sets whether to catch exceptions while running or not.
     *
     * @param {boolean} catchExceptions
     */
    set catchExceptions(catchExceptions) {
        this._catchExceptions = catchExceptions;
    }

    /**
     * Sets if application should automatically terminate when run
     * has been completed.
     *
     * @param {boolean} autoExit
     */
    set autoExit(autoExit) {
        this._autoExit = autoExit;
    }

    /**
     * Run the application
     *
     * @param {Jymfony.Component.Console.Input.InputInterface} input
     * @param {Jymfony.Component.Console.Output.OutputInterface} output
     *
     * @returns {Promise} Promise executing the application
     */
    run(input = new ArgvInput(), output = new ConsoleOutput()) {
        this._configureIO(input, output);

        let promise = __jymfony.Async.run(this._doRun(input, output));

        if (this._catchExceptions) {
            promise = promise
                .catch((exception) => {
                    if (output instanceof ConsoleOutputInterface) {
                        this._renderException(exception, output.errorOutput);
                    } else {
                        this._renderException(exception, output);
                    }

                    let exitCode = exception.code || 1;
                    if (! isNumber(exitCode)) {
                        exitCode = 1;
                    }

                    if (255 < exitCode) {
                        exitCode = 255;
                    }

                    return exitCode;
                })
                .then(exitCode => {
                    if (this._autoExit) {
                        // Wait for next uncork call.
                        process.nextTick(() => process.exit(exitCode));
                    }

                    return process.exitCode = exitCode;
                })
            ;
        }

        return promise;
    }

    /**
     * Returns the long version of the application.
     *
     * @returns {string} The long application version
     */
    getLongVersion() {
        if ('UNKNOWN' !== this.name) {
            if ('UNKNOWN' !== this.version) {
                return util.format('%s <info>%s</info>', this.name, this.version);
            }

            return this.name;
        }

        return 'Console Tool';
    }

    /**
     * Registers a new command.
{'fraction_non_alphanumeric': 0.09839240751501065, 'fraction_numerical': 0.0015494867325198528, 'mean_word_length': 2.0872944693572495, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3173581', 'n_tokens_mistral': 2692, 'n_tokens_neox': 2592, 'n_words': 587}