<commit_before>/// <reference path="../../definitions/node/node.d.ts"/>
/// <reference path="../../definitions/colors/colors.d.ts"/>

import fs = require('fs');
import path = require('path');
import cm = require('./common');
import colors = require('colors');

export function load(execPath: string, cmds: string[], defaultCmd: string): any {   
    var module = null;

    var execCmds: string[] = null;
    try {
        execCmds = fs.readdirSync(execPath);
    }
    catch(err) {
        return module;
    }

    var match = this.match(execCmds, cmds) || defaultCmd;
    if (match) {
        module = require(path.join(execPath, match));
    }
    
    return { name: path.basename(match, '.js'), module: module };   
}

export function match(cmdList: string[], cmds: string[]): string {
    var candidates = [];

    for (var i = 0; i < cmds.length; i++) {
        var candidate = '';
        for (var j = 0; j <= i; j++) {
            if (j > 0) {
                candidate += '-';
            }

            candidate += cmds[j];
        }
        candidates.push(candidate);
    }

    // let's find the most specific command
    candidates = candidates.reverse();

    var match = null;
    candidates.some((candidate) => {
        var file = candidate + '.js';
        var i = cmdList.indexOf(file);
        if (i >= 0) {
            match = file;
            return true;
        }
    })

    return match;
}

export function getHelp(execPath: string, scope: string, all: boolean) {
    var ssc = scope == '' ? 0 : scope.split('-').length;
    var execCmds = execCmds = fs.readdirSync(execPath);

    console.log();
    console.log(colors.magenta('                        fTfs         '));   
    console.log(colors.magenta('                      fSSSSSSSs      '));
    console.log(colors.magenta('                     fSSSSSSSSSS     '));
    console.log(colors.magenta('     TSSf         fSSSSSSSSSSSS      '));
    console.log(colors.magenta('     SSSSSF     fSSSSSSST SSSSS      '));
    console.log(colors.magenta('     SSfSSSSSsfSSSSSSSt   SSSSS      '));
    console.log(colors.magenta('     SS  tSSSSSSSSSs      SSSSS      '));
    console.log(colors.magenta('     SS   fSSSSSSST       SSSSS      '));
    console.log(colors.magenta('     SS fSSSSSFSSSSSSf    SSSSS      '));
    console.log(colors.magenta('     SSSSSST    FSSSSSSFt SSSSS      '));
    console.log(colors.magenta('     SSSSt        FSSSSSSSSSSSS      '));
    console.log(colors.magenta('                    FSSSSSSSSSS      '));
    console.log(colors.magenta('                       FSSSSSSs      '));
    console.log(colors.magenta('                        FSFs    (TM) '));
    console.log();
    console.log(colors.cyan('commands:'));

    execCmds.forEach((cmd) => {
        cmd = path.basename(cmd, '.js');
        //console.log('\n' + cmd);

        //var show = false;
        var cs = cmd.split('-');
        var csc = cs.length;
        //console.log(scope, ssc, csc, all);<commit_msg>one char off<commit_after>/// <reference path="../../definitions/node/node.d.ts"/>
/// <reference path="../../definitions/colors/colors.d.ts"/>

import fs = require('fs');
import path = require('path');
import cm = require('./common');
import colors = require('colors');

export function load(execPath: string, cmds: string[], defaultCmd: string): any {   
    var module = null;

    var execCmds: string[] = null;
    try {
        execCmds = fs.readdirSync(execPath);
    }
    catch(err) {
        return module;
    }

    var match = this.match(execCmds, cmds) || defaultCmd;
    if (match) {
        module = require(path.join(execPath, match));
    }
    
    return { name: path.basename(match, '.js'), module: module };   
}

export function match(cmdList: string[], cmds: string[]): string {
    var candidates = [];

    for (var i = 0; i < cmds.length; i++) {
        var candidate = '';
        for (var j = 0; j <= i; j++) {
            if (j > 0) {
                candidate += '-';
            }

            candidate += cmds[j];
        }
        candidates.push(candidate);
    }

    // let's find the most specific command
    candidates = candidates.reverse();

    var match = null;
    candidates.some((candidate) => {
        var file = candidate + '.js';
        var i = cmdList.indexOf(file);
        if (i >= 0) {
            match = file;
            return true;
        }
    })

    return match;
}

export function getHelp(execPath: string, scope: string, all: boolean) {
    var ssc = scope == '' ? 0 : scope.split('-').length;
    var execCmds = execCmds = fs.readdirSync(execPath);

    console.log();
    console.log(colors.magenta('                        fTfs         '));   
    console.log(colors.magenta('                      fSSSSSSSs      '));
    console.log(colors.magenta('                    fSSSSSSSSSS     '));
    console.log(colors.magenta('     TSSf         fSSSSSSSSSSSS      '));
    console.log(colors.magenta('     SSSSSF     fSSSSSSST SSSSS      '));
    console.log(colors.magenta('     SSfSSSSSsfSSSSSSSt   SSSSS      '));
    console.log(colors.magenta('     SS  tSSSSSSSSSs      SSSSS      '));
    console.log(colors.magenta('     SS   fSSSSSSST       SSSSS      '));
    console.log(colors.magenta('     SS fSSSSSFSSSSSSf    SSSSS      '));
    console.log(colors.magenta('     SSSSSST    FSSSSSSFt SSSSS      '));
    console.log(colors.magenta('     SSSSt        FSSSSSSSSSSSS      '));
    console.log(colors.magenta('                    FSSSSSSSSSS      '));
    console.log(colors.magenta('                       FSSSSSSs      '));
    console.log(colors.magenta('                        FSFs    (TM) '));
    console.log();
    console.log(colors.cyan('commands:'));

    execCmds.forEach((cmd) => {
        cmd = path.basename(cmd, '.js');
        //console.log('\n' + cmd);

        //var show = false;
        var cs = cmd.split('-');
        var csc = cs.length;
        //console.log(scope, ssc, csc, all);
{'fraction_non_alphanumeric': 0.153485254691689, 'fraction_numerical': 0.001675603217158177, 'mean_word_length': 1.866954851104707, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 18, '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': '1827048', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1902, 'n_words': 393}