<commit_before>import {IMakestuffConfig, INormalizedOption, INormalizedOutputFile} from "../generator/interfaces";
import GeneratorShell from "../shell/shell";
import {ConsoleReporter} from "../reporter/console-reporter";

export default class MakestuffCli {
    private shell: GeneratorShell;

    constructor(private workdir: string, private config: IMakestuffConfig) {
        this.shell = new GeneratorShell(this.config);
    }

    run(cliEngine: Caporal) {
        this.setupCli(cliEngine);
        cliEngine.parse(process.argv);
    }

    private setupCli(cliEngine: Caporal) {
        this.shell.generators.forEach((generator) => {
            const config = generator.config;
            const cliCommand = cliEngine.command(config.name, config.description)
                .argument("<path>", "Path to generated entity with name in the end");

            this.registerOutputOptions(config.optionalOutput, cliCommand, cliEngine);
            this.registerOptions(config.options, cliCommand);

            cliCommand.action((args: Record<string, string>, options: Record<string, any>, logger: Logger) => {
                const reporter = new ConsoleReporter(logger);
                logger.debug(`Workdir: ${this.workdir}`);

                const optionsList = this.getEnabledBooleanOptions(options);
                const result = this.shell.run(this.workdir, config.name, args.path, optionsList);

                reporter.printGeneratorResult(result);
            });

            this.registerFullOption(cliCommand, cliEngine);
        });
    }

    private registerOptions(options: Array<INormalizedOption>, cliCommand: Command) {
        options.forEach((option) => {
            cliCommand.option(option.name, option.description);
        });
    }

    /**
     * @deprecated
     */
    private registerOutputOptions(<commit_msg>refactor: move generator setup logic into the separate method<commit_after>import Generator from "../generator/generator";
import {IMakestuffConfig, INormalizedOption, INormalizedOutputFile} from "../generator/interfaces";
import GeneratorShell from "../shell/shell";
import {ConsoleReporter} from "../reporter/console-reporter";

export default class MakestuffCli {
    private shell: GeneratorShell;

    constructor(private workdir: string, private config: IMakestuffConfig) {
        this.shell = new GeneratorShell(this.config);
    }

    run(cliEngine: Caporal) {
        this.setupCli(cliEngine);
        cliEngine.parse(process.argv);
    }

    private setupCli(cliEngine: Caporal) {
        this.shell.generators.forEach((generator) => {
            this.setupGenerator(generator, cliEngine);
        });
    }

    private setupGenerator(generator: Generator, cliEngine: Caporal) {
        const config = generator.config;
        const cliCommand = cliEngine.command(config.name, config.description)
            .argument("<path>", "Path to generated entity with name in the end");

        this.registerOutputOptions(config.optionalOutput, cliCommand, cliEngine);
        this.registerOptions(config.options, cliCommand);

        cliCommand.action((args: Record<string, string>, options: Record<string, any>, logger: Logger) => {
            const reporter = new ConsoleReporter(logger);
            logger.debug(`Workdir: ${this.workdir}`);

            const optionsList = this.getEnabledBooleanOptions(options);
            const result = this.shell.run(this.workdir, config.name, args.path, optionsList);

            reporter.printGeneratorResult(result);
        });

        this.registerFullOption(cliCommand, cliEngine);
    }

    private registerOptions(options: Array<INormalizedOption>, cliCommand: Command) {
        options.forEach((option) => {
            cliCommand.option(option.name, option.description);
        });
    }

    /**
     * @deprecated
     */
    private registerOutputOptions(
{'fraction_non_alphanumeric': 0.11240010311936066, 'fraction_numerical': 0.0, 'mean_word_length': 3.0332640332640333, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, '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': '5581333', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1000, 'n_words': 212}