<commit_before>/* jshint esnext: true */

var argv = require('minimist')(process.argv.slice(2));

var targetDB = argv.db || docs();
var host = argv._[0] || docs();
var prefixes = argv.prefix;

if (prefixes) {
  prefixes = prefixes.split(',');
}

var nano = require('nano')(host);
var feed = nano.followUpdates({});

var replicate = function(source, target) {
  nano.db.replicate(source, target, { create_target:true }, function(error, body) {
    if (error) {
      return console.log(error);
    }
  });
};

feed.on('change', function(change) {
  if (change.type === 'updated') {
    var dbName = change.db_name;

    if (dbName === targetDB) {
      return;
    }

    if (prefixes) {
      for (var prefix of prefixes) {
        if (dbName.indexOf(prefix) === 0) {
          return replicate(dbName, targetDB);
        }
      }
    }
  }
});

feed.follow();

function docs() {
  usage();
  options();

  process.exit(1);
}

function usage() {
  console.log("Usage: node index.js --db=mainDB [--prefix=m/,c/] http://user:pass@host.com\n");
}

function options() {
  console.log('Options:');
  console.log('  --db      The target database to replicate to.');
  console.log('  --prefix  Only replicate databases with these comma-separated prefixes.');
}<commit_msg>Log replication errors<commit_after>/* jshint esnext: true */

var argv = require('minimist')(process.argv.slice(2));

var targetDB = argv.db || docs();
var host = argv._[0] || docs();
var prefixes = argv.prefix;

if (prefixes) {
  prefixes = prefixes.split(',');
}

var nano = require('nano')(host);
var feed = nano.followUpdates({});

var replicate = function(source, target) {
  nano.db.replicate(source, target, { create_target:true }, function(error, body) {
    if (error) {
      return console.log(error);
    }
  });
};

feed.on('change', function(change) {
  if (change.type === 'updated') {
    var dbName = change.db_name;

    if (dbName === targetDB) {
      return;
    }

    var callback = function(error, body) {
      if (error) {
        return console.log(error, body);
      }
    };

    if (prefixes) {
      for (var prefix of prefixes) {
        if (dbName.indexOf(prefix) === 0) {
          return replicate(dbName, targetDB, {create_target: true}, callback);
        }
      }
    }
  }
});

feed.follow();

function docs() {
  usage();
  options();

  process.exit(1);
}

function usage() {
  console.log("Usage: node index.js --db=mainDB [--prefix=m/,c/] http://user:pass@host.com\n");
}

function options() {
  console.log('Options:');
  console.log('  --db      The target database to replicate to.');
  console.log('  --prefix  Only replicate databases with these comma-separated prefixes.');
}
{'fraction_non_alphanumeric': 0.1778685480876346, 'fraction_numerical': 0.0029706646862235424, 'mean_word_length': 3.081818181818182, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '3759494', 'n_tokens_mistral': 932, 'n_tokens_neox': 900, 'n_words': 214}