<commit_before>const chalk = require('chalk');

const help = require('./help');

function getPackageName(packageName) {
    if (packageName.match(/^swagen-/i)) {
        return packageName;
    }
    return `swagen-${packageName}`;
}

function displayHelp(errorMessage) {
    console.log(chalk.red(errorMessage));
    console.log();
    for (let i = 0; i < help.length; i++) {
        console.log(help[i]);
    }
}

module.exports = function(args) {
    if (args._.length === 0) {
        displayHelp('Specify a package name.');
        return;
    }
    const packageName = getPackageName(args._[0]);
    let generatorPkg;
    try {
        generatorPkg = require(packageName);
    } catch (ex) {
        console.error(`Cannot load generator package named ${packageName}.`);
        return;
    }
    const modes = generatorPkg instanceof Array ? generatorPkg : [generatorPkg];
    for (const mode of modes) {
        console.log(`Name       : ${mode.name}`);
        console.log(`Description: ${mode.description}`);
        console.log(`Language   : ${mode.language} (ext: .${mode.extension})`);
        console.log();
    }
};
<commit_msg>Cleaned modes command implementation<commit_after>'use strict';

function getPackageName(packageName) {
    if (packageName.match(/^swagen-/i)) {
        return packageName;
    }
    return `swagen-${packageName}`;
}

module.exports = function(args) {
    // Process arguments
    if (args._.length === 0) {
        throw new Error(`Specify a package name.`);
    }
    const packageName = getPackageName(args._[0]);

    // Load generator and modes
    let generator;
    try {
        generator = require(packageName);
    } catch (ex) {
        throw new Error(`Cannot load generator package named ${packageName}.`);
    }
    const modes = generator instanceof Array ? generator : [generator];

    // Iterate over modes and display the details
    for (const mode of modes) {
        console.log(`Name       : ${mode.name}`);
        console.log(`Description: ${mode.description}`);
        console.log(`Language   : ${mode.language} (ext: .${mode.extension})`);
        console.log();
    }
};

{'fraction_non_alphanumeric': 0.14839010732617824, 'fraction_numerical': 0.0023331777881474567, 'mean_word_length': 2.76140350877193, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '1731927', 'n_tokens_mistral': 627, 'n_tokens_neox': 632, 'n_words': 150}