<commit_before>/* exported main */

const System = imports.system;

function lowerFirst(string) {
    return string[0].toLowerCase() + string.slice(1);
}

function main() {
    if (ARGV.length !== 1 || ARGV[0] == '--help' || ARGV[0] == '-h') {
        printerr('Supply a module name, such as Filter.Unread.');
        printerr('Pipe to `jq .` or `python -m json.tool` to pretty-print.');
        System.exit(1);
    }

    let module_name = ARGV[0];
    let module_path = module_name.split('.');
    let classname = module_path[module_path.length - 1];
    module_path = module_path.map(lowerFirst);
    let module = module_path.reduce((prev, curr) => prev[curr],
        imports.app.modules);
    print(JSON.stringify(module[classname].introspect()));
    System.exit(0);
}
<commit_msg>introspect: Support absolute file paths<commit_after>/* exported main */

const Gio = imports.gi.Gio;
const System = imports.system;

function upperFirst(string) {
    return string[0].toUpperCase() + string.slice(1);
}

function lowerFirst(string) {
    return string[0].toLowerCase() + string.slice(1);
}

function main() {
    if (ARGV.length < 1 || ARGV.length > 2 ||
        ARGV[0] == '--help' || ARGV[0] == '-h' ||
        (ARGV.length === 2 && ARGV[0] !== '--file')) {
        printerr('Supply a module name, such as Filter.Unread.');
        printerr('Or supply a JS file name with --file.');
        printerr('Pipe to `jq .` or `python -m json.tool` to pretty-print.');
        System.exit(1);
    }

    let classname, module_path, importer;
    if (ARGV[0] === '--file') {
        let module_name = Gio.File.new_for_commandline_arg(ARGV[1]).get_path();
        if (module_name.endsWith('.js'))
            module_name = module_name.slice(0, -3);
        module_path = module_name.split('/');
        classname = upperFirst(module_path[module_path.length - 1]);
        importer = imports['.'];
        importer.searchPath = ['/'];
    } else {
        let module_name = ARGV[0];
        module_path = module_name.split('.');
        classname = module_path[module_path.length - 1];
        module_path = module_path.map(lowerFirst);
        importer = imports.app.modules;
    }

    let module = module_path.reduce((prev, curr) => prev[curr], importer);
    print(JSON.stringify(module[classname].introspect()));
    System.exit(0);
}

{'fraction_non_alphanumeric': 0.1683083511777302, 'fraction_numerical': 0.011991434689507495, 'mean_word_length': 2.9593220338983053, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '310334', 'n_tokens_mistral': 781, 'n_tokens_neox': 777, 'n_words': 164}