<commit_before>#!/usr/bin/env node

import { Switch }  from '../index';
import { join } from 'path';
import { getConfig, IActions } from '../config';
import { OptionHandler } from '../optionHandler';
import { options } from '../options';

/**
 * Get rid of the first to arguments under process.argv
 */
function cleanArgs() {
    process.argv.shift();
    process.argv.shift();
}

function printHelp (actions: IActions) {
    console.log('\nParent action not found\n\nAvailable Actions:');

    for (let action in actions) {
        console.log(`  ${action}\t${actions[action]}`);
    }

    console.log();
}

function getParentActionDirectory (actions: IActions): string | null {
    let parentAction = process.argv.shift();

    if (!parentAction || !actions[parentAction]) return null;

    return actions[parentAction];
}

function run () {
    let config = getConfig();

    // Get rid of the first two arguments
    cleanArgs();

    let optionHandler = new OptionHandler(options);

    if (optionHandler.hasOptions) {
        return optionHandler.runAllOptions();
    }

    let parentActionDirectory = getParentActionDirectory(config.actions);

    if (parentActionDirectory) {
        // Create a new Switch at the root level of actions
        new Switch('', parentActionDirectory);
    } else {
        printHelp(config.actions);
    }
}

run();<commit_msg>Added comments to action.ts<commit_after>#!/usr/bin/env node

import { Switch }  from '../index';
import { join } from 'path';
import { getConfig, IActions } from '../config';
import { OptionHandler } from '../optionHandler';
import { options } from '../options';

/**
 * Get rid of the first to arguments under process.argv
 */
function cleanArgs() {
    process.argv.shift();
    process.argv.shift();
}

/**
 * Print a helper message with all available actions
 * 
 * @param actions The IActions object
 */
function printHelp (actions: IActions) {
    console.log('\nParent action not found\n\nAvailable Actions:');

    for (let action in actions) {
        console.log(`  ${action}\t${actions[action]}`);
    }

    console.log();
}

/**
 * Get the directory for the parent action from the IActions object
 * or return null if it doesn't exit
 * 
 * @param actions The IActions object
 */
function getParentActionDirectory (actions: IActions): string | null {
    let parentAction = process.argv.shift();

    if (!parentAction || !actions[parentAction]) return null;

    return actions[parentAction];
}

/**
 * The main runner function
 */
function run () {
    // Get the config
    let config = getConfig();

    // Get rid of the first two arguments
    cleanArgs();

    // Get a new OptionHandler with the action-runner options
    let optionHandler = new OptionHandler(options);

    if (optionHandler.hasOptions) {
        // If it has options, run them and end the application
        return optionHandler.runAllOptions();
    }

    // Get the parent directory for the given action
    let parentActionDirectory = getParentActionDirectory(config.actions);

    if (parentActionDirectory) {
        // Create the Switch to handle the rest
        new Switch('', parentActionDirectory);
    } else {
        // If we couldn't get a parent directory, then then the action
        // doesn't exist in the config.
        printHelp(config.actions);
    }
}

// Run the runner function
run();
{'fraction_non_alphanumeric': 0.12195845697329377, 'fraction_numerical': 0.0, 'mean_word_length': 3.076178960096735, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1500887', 'n_tokens_mistral': 923, 'n_tokens_neox': 897, 'n_words': 310}