<commit_before>/* 
 *
 * Mongo Hacker
 * MongoDB Shell Enhancements for Hackers 
 *
 * <NAME> - 2012
 *
 * http://tylerbrock.github.com/mongo-hacker
 *
 */

__ansi = {
    csi: String.fromCharCode(0x1B) + '[',
    reset: '0',
    text_prop: 'm',
    foreground: '3',
    bright: '1',
    underline: '4',

    colors: {
        red: '1',
        green: '2',
        yellow: '3',
        blue: '4',
        magenta: '5',
        cyan: '6'  
    }
}

if (_isWindows()) {
  print("\nSorry! MongoDB Shell Enhancements for Hackers isn't compatible with Windows.\n");
}

var ver = db.version().split(".");
if ( ver[0] <= parseInt("2") && ver[1] < parseInt("2") ) {
  print(colorize("\nSorry! Mongo version 2.2.x and above is required! Please upgrade.\n", "red", true));
} 

setVerboseShell(true);
setIndexParanoia(true);
setAutoMulti(true);

__indent = "  "

function setIndexParanoia( value ) { 
    if( value == undefined ) value = true; 
    _indexParanoia = value; 
}

function setAutoMulti( value ) { 
    if( value == undefined ) value = true; 
    _autoMulti = value; 
}

function controlCode( parameters ) {
    if ( parameters == undefined ) {
    	parameters = "";
    }
    else if (typeof(parameters) == 'object' && (parameters instanceof Array)) {
        parameters = parameters.join(';');
    }

    return __ansi.csi + String(parameters) + String(__ansi.text_prop);
}

function applyColorCode( string, properties ) {
    return controlCode(properties) + String(string) + controlCode();
}

function colorize( string, color, bright, underline ) {
    var params = [];
    var code = __ansi.foreground + __ansi.colors[color];

    params.push(code);

    if ( bright == true ) params.push(__ansi.bright);
    if ( underline == true ) params.push(__ansi.underline);

    return applyColorCode( string, params );
}

ObjectId.prototype.toString = function() {
    return this.str;
}

ObjectId.prototype.tojson = function(indent, nolint) {
    return tojson(this);
}

DBQuery.prototype._validate = function( o ){
    var firstKey = null;
    for (var k in o) { firstKey = k; break; }

    if (firstKey != null && firstKey[0] == '$') {
        // for mods we only validate partially, for example keys may have dots
        this._validateObject( o );
    } else {
        // we're basically inserting a brand new object, do full validation
        this._validateForStorage( o );
    }
}

DBQuery.prototype._validateObject = function( o ){
    if (typeof(o) != "object")
        throw "attempted to save a " + typeof(o) + " value.  document expected.";

    if ( o._ensureSpecial && o._checkModify )
        throw "can't save a DBQuery object";
}
<commit_msg>add ability to get environment variables from mongo shell<commit_after>/* 
 *
 * Mongo Hacker
 * MongoDB Shell Enhancements for Hackers 
 *
 * <NAME> - 2012
 *
 * http://tylerbrock.github.com/mongo-hacker
 *
 */

__ansi = {
    csi: String.fromCharCode(0x1B) + '[',
    reset: '0',
    text_prop: 'm',
    foreground: '3',
    bright: '1',
    underline: '4',

    colors: {
        red: '1',
        green: '2',
        yellow: '3',
        blue: '4',
        magenta: '5',
        cyan: '6'  
    }
}

if (_isWindows()) {
  print("\nSorry! MongoDB Shell Enhancements for Hackers isn't compatible with Windows.\n");
}

var ver = db.version().split(".");
if ( ver[0] <= parseInt("2") && ver[1] < parseInt("2") ) {
  print(colorize("\nSorry! Mongo version 2.2.x and above is required! Please upgrade.\n", "red", true));
} 

setVerboseShell(true);
setIndexParanoia(true);
setAutoMulti(true);

__indent = "  "

function setIndexParanoia( value ) { 
    if( value == undefined ) value = true; 
    _indexParanoia = value; 
}

function setAutoMulti( value ) { 
    if( value == undefined ) value = true; 
    _autoMulti = value; 
}

function controlCode( parameters ) {
    if ( parameters == undefined ) {
    	parameters = "";
    }
    else if (typeof(parameters) == 'object' && (parameters instanceof Array)) {
        parameters = parameters.join(';');
    }

    return __ansi.csi + String(parameters) + String(__ansi.text_prop);
}

function applyColorCode( string, properties ) {
    return controlCode(properties) + String(string) + controlCode();
}

function colorize( string, color, bright, underline ) {
    var params = [];
    var code = __ansi.foreground + __ansi.colors[color];

    params.push(code);

    if ( bright == true ) params.push(__ansi.bright);
    if ( underline == true ) params.push(__ansi.underline);

    return applyColorCode( string, params );
}

function getEnv(env_var){
    clearRawMongoProgramOutput();
    run('env');
    var env = rawMongoProgramOutput();
    var env_regex = new RegExp(env_var + '=(.*)');
    return env.match(env_regex)[1];
}

ObjectId.prototype.toString = function() {
    return this.str;
}

ObjectId.prototype.tojson = function(indent, nolint) {
    return tojson(this);
}

DBQuery.prototype._validate = function( o ){
    var firstKey = null;
    for (var k in o) { firstKey = k; break; }

    if (firstKey != null && firstKey[0] == '$') {
        // for mods we only validate partially, for example keys may have dots
        this._validateObject( o );
    } else {
        // we're basically inserting a brand new object, do full validation
        this._validateForStorage( o );
    }
}

DBQuery.prototype._validateObject = function( o ){
    if (typeof(o) != "object")
        throw "attempted to save a " + typeof(o) + " value.  document expected.";

    if ( o._ensureSpecial && o._checkModify )
        throw "can't save a DBQuery object";
}

{'fraction_non_alphanumeric': 0.14699011680143756, 'fraction_numerical': 0.008445642407906559, 'mean_word_length': 2.9587482219061165, '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': '1823485', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1784, 'n_words': 469}