<commit_before>var path = require('path');

/*  Hack an instance of Argv with process.argv into Argv
    so people an do
        require('optimist')(['--beeble=1','-z','zizzle']).argv
    to parse a list of args and
        require('optimist').argv
    to get a parsed version of process.argv.
*/
var inst = Argv(process.argv.slice(2));
Object.keys(inst).forEach(function (key) {
    Argv[key] = typeof inst[key] == 'function'
        ? inst[key].bind(inst)
        : inst[key];
});

var exports = module.exports = Argv;
function Argv (args, cwd) {
    var self = {};
    if (!cwd) cwd = process.cwd();
    
    self.$0 = process.argv
        .slice(0,2)
        .map(function (x) {
            var b = rebase(cwd, x);
            return x.match(/^\//) && b.length < x.length
                ? b : x
        })
        .join(' ')
    ;
    
    if (process.argv[1] == process.env._) {
        self.$0 = process.env._.replace(
            path.dirname(process.execPath) + '/', ''
        );
    }
    
    var flags = { bools : {}, strings : {} };
    
    self.boolean = function (bools) {
        if (!Array.isArray(bools)) {
            bools = [].slice.call(arguments);
        }
        
        bools.forEach(function (name) {
            flags.bools[name] = true;
        });
        
        bools.forEach(function (name) {
            if (!self.argv[name]) {
                self.argv[name] = false;
            }
        });
        
        return self;
    };
    
    self.string = function (strings) {
        if (!Array.isArray(strings)) {
            strings = [].slice.call(arguments);
        }
        
        strings.forEach(function (name) {
            flags.strings[name] = true;
        });
        
        return self;
    };
    
    var aliases = {};
    self.alias = function (x, y) {
        if (typeof x === 'object') {
            Object.keys(x).forEach(function (key) {
                aliases[key] = x[key];
                aliases[x[key]] = key;
            });
        }
        else if (Array.isArray(y)) {
            y.forEach(function (yy) {
                self.alias(x, y);
            });
        }
        else {
            aliases[x] = y;
            aliases[y] = x;
        }
        
        return self;
    };
    
    var demanded = {};
    self.demand = function (keys, cb) {
        if (typeof keys == 'number') {
            if (!demanded._) demanded._ = 0;
            demanded._ += keys;
        }
        else if (Array.isArray(keys)) {
            keys.forEach(function (key) {
                self.demand(key);
            });
        }
        else {
            demanded[keys] = true;
        }
        
        return self;
    };
    
    var usage;
    self.usage = function (msg, opts) {
        if (!opts && typeof msg === 'object') {
            opts = msg;
            msg = null;
        }
        
        usage = msg;
        
        if (opts) self.options(opts);
        
        return self;
    };
    
    function fail (msg) {
        self.showHelp();
        if (msg) console.error(msg);
        process.exit(1);
    }
    
    self.check = function (f) {
        try {
            if (f(self.argv) === false) fail(
                'Argument check failed: ' + f.toString()
            );
        }
        catch (err) { fail(err) }
        
        return self;
    };
    
    var defaults = {};
    self.default = function (key, value) {
        if (typeof key === 'object') {
            Object.keys(key).forEach(function (k) {
                defaults[k] = key[k];
            });
        }
        else {
            defaults[key] = value;
        }
        
        return self;
    };
    
    self.parse = function (args) {
        return Argv(args).argv;
    };
    
    self.camelCase = function () {
        for (var key in self.argv) {
            var camelCasedKey = key.replace(/-([a-z])/g, function (_, c) {
                return c.toUpperCase();
            });
            
            if (camelCasedKey !== key) {
                self.argv[camelCasedKey] = self.argv[key];
                delete self.argv[key];
            }
        }
        return self;
    };
    
    function longestElement (a) {
        var l = 0;
        for (var i = 0; i < a.length; i++) {
            if (a[l].length < a[i].length) {
                l = i;
            }
        }

        return a[l].length;
    }
    
    self.options = function (opts) {
        Object.keys(opts).forEach(function (key) {
            var opt = opts[key];
            
            if (opt.alias) self.alias(key, opt.alias);
            if (opt.demand) self.demand(key);
            if (opt.default) self.default(key, opt.default);
            
            if (opt.boolean || opt.type === 'boolean') {
                self.boolean(key);
            }
            if (opt.string || opt.type === 'string') {
                self.string(key);
            }
        });
        
        return self;
    };
    
    self.showHelp = function (padding) {
        if (usage) {
            console.error(usage.replace(/\$0/g, self.$0));
        }
        
        if (self.options && Object.keys(self.options).length > 0) {
            var help = Object.keys(self.options).map(function (key) {
                var o = self.options[key];
                var hargs = [o.short, key]; 
                
                hargs = hargs.filter(function (a) { 
                    return a; 
                }).map(function (a) {
                    return a.length === 1 ? '-' + a : '--' + a;
                }).join(', ');
          
                return {
                    args: hargs,<commit_msg>let .options() take single options too<commit_after>var path = require('path');

/*  Hack an instance of Argv with process.argv into Argv
    so people an do
        require('optimist')(['--beeble=1','-z','zizzle']).argv
    to parse a list of args and
        require('optimist').argv
    to get a parsed version of process.argv.
*/
var inst = Argv(process.argv.slice(2));
Object.keys(inst).forEach(function (key) {
    Argv[key] = typeof inst[key] == 'function'
        ? inst[key].bind(inst)
        : inst[key];
});

var exports = module.exports = Argv;
function Argv (args, cwd) {
    var self = {};
    if (!cwd) cwd = process.cwd();
    
    self.$0 = process.argv
        .slice(0,2)
        .map(function (x) {
            var b = rebase(cwd, x);
            return x.match(/^\//) && b.length < x.length
                ? b : x
        })
        .join(' ')
    ;
    
    if (process.argv[1] == process.env._) {
        self.$0 = process.env._.replace(
            path.dirname(process.execPath) + '/', ''
        );
    }
    
    var flags = { bools : {}, strings : {} };
    
    self.boolean = function (bools) {
        if (!Array.isArray(bools)) {
            bools = [].slice.call(arguments);
        }
        
        bools.forEach(function (name) {
            flags.bools[name] = true;
        });
        
        bools.forEach(function (name) {
            if (!self.argv[name]) {
                self.argv[name] = false;
            }
        });
        
        return self;
    };
    
    self.string = function (strings) {
        if (!Array.isArray(strings)) {
            strings = [].slice.call(arguments);
        }
        
        strings.forEach(function (name) {
            flags.strings[name] = true;
        });
        
        return self;
    };
    
    var aliases = {};
    self.alias = function (x, y) {
        if (typeof x === 'object') {
            Object.keys(x).forEach(function (key) {
                aliases[key] = x[key];
                aliases[x[key]] = key;
            });
        }
        else if (Array.isArray(y)) {
            y.forEach(function (yy) {
                self.alias(x, y);
            });
        }
        else {
            aliases[x] = y;
            aliases[y] = x;
        }
        
        return self;
    };
    
    var demanded = {};
    self.demand = function (keys, cb) {
        if (typeof keys == 'number') {
            if (!demanded._) demanded._ = 0;
            demanded._ += keys;
        }
        else if (Array.isArray(keys)) {
            keys.forEach(function (key) {
                self.demand(key);
            });
        }
        else {
            demanded[keys] = true;
        }
        
        return self;
    };
    
    var usage;
    self.usage = function (msg, opts) {
        if (!opts && typeof msg === 'object') {
            opts = msg;
            msg = null;
        }
        
        usage = msg;
        
        if (opts) self.options(opts);
        
        return self;
    };
    
    function fail (msg) {
        self.showHelp();
        if (msg) console.error(msg);
        process.exit(1);
    }
    
    self.check = function (f) {
        try {
            if (f(self.argv) === false) fail(
                'Argument check failed: ' + f.toString()
            );
        }
        catch (err) { fail(err) }
        
        return self;
    };
    
    var defaults = {};
    self.default = function (key, value) {
        if (typeof key === 'object') {
            Object.keys(key).forEach(function (k) {
                defaults[k] = key[k];
            });
        }
        else {
            defaults[key] = value;
        }
        
        return self;
    };
    
    self.parse = function (args) {
        return Argv(args).argv;
    };
    
    self.camelCase = function () {
        for (var key in self.argv) {
            var camelCasedKey = key.replace(/-([a-z])/g, function (_, c) {
                return c.toUpperCase();
            });
            
            if (camelCasedKey !== key) {
                self.argv[camelCasedKey] = self.argv[key];
                delete self.argv[key];
            }
        }
        return self;
    };
    
    function longestElement (a) {
        var l = 0;
        for (var i = 0; i < a.length; i++) {
            if (a[l].length < a[i].length) {
                l = i;
            }
        }

        return a[l].length;
    }
    
    self.options = function (key, opt) {
        if (typeof key === 'object') {
            Object.keys(key).forEach(function (k) {
                self.options(k, key[k]);
            });
        }
        else {
            var opt = opts[key];
            
            if (opt.alias) self.alias(key, opt.alias);
            if (opt.demand) self.demand(key);
            if (opt.default) self.default(key, opt.default);
            
            if (opt.boolean || opt.type === 'boolean') {
                self.boolean(key);
            }
            if (opt.string || opt.type === 'string') {
                self.string(key);
            }
            
            var desc = opt.describe || opt.description || opt.desc;
            if (desc) {
                self.describe(key, desc);
            }
        }
        
        return self;
    };
    
    self.showHelp = function (padding) {
        if (usage) {
            console.error(usage.replace(/\$0/g, self.$0));
        }
        
        if (self.options && Object.keys(self.options).length > 0) {
            var help = Object.keys(self.options).map(function (key) {
                var o = self.options[key];
                var hargs = [o.short, key]; 
                
                hargs = hargs.filter(function (a) { 
                    return a; 
                }).map(function (a) {
                    return a.length === 1 ? '-' + a : '--' + a;
                }).join(', ');
          
                return {
                    args: hargs,
{'fraction_non_alphanumeric': 0.14492503877304844, 'fraction_numerical': 0.0025848698948819577, 'mean_word_length': 1.1949697428139183, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '4831424', 'n_tokens_mistral': 3502, 'n_tokens_neox': 3437, 'n_words': 731}