<commit_before>"use strict";

var clc = require('cli-color');
var read = require('read')
var spawn = require('child_process').spawn;
var rek = require('rekuire');

var linksDataUtils = rek('linksDataUtils');
var waiting = rek('waiting');
var linksData = rek('linksData');

module.exports = {
  link: link
};

function link(linkData) {
  this.data = linkData;
}

link.prototype.run = function(wet) {
  if (!linksDataUtils.varify(this.data)) {
    return console.log(clc.red("Link invalid! \nMaybe you forgot to connect a drive or to mount a file system?"));
  }
  this.wet = wet;
  this.promptForExecution();
}

////////////////////////////////////////////////////////////////////////////////

link.prototype.promptForExecution = function() {
  this.parseCommandArgs();
  read({prompt: this.parsePrompt()}, function(error, input, isDefault) {
    if (error) {
      return console.log(clc.red("Error handling input, or input invalid!"));
    } else if (isAnswerPositive(input, this.wet)) {
      this.execute();
    }
  }.bind(this));
}

link.prototype.execute = function() {
  var command = spawn('rsync', this.commandArgs);
  command.stdout.on('data', this.stdout.bind(this));
  command.stderr.on('data', this.stderr.bind(this));
  command.on('exit', this.onExit.bind(this));
}

link.prototype.parseCommandArgs = function() {
  this.commandArgs = [this.data.source, this.data.target, "-Phavyx", "--delete-after", "--dry-run"];
  if (this.wet) {
    var dryIndex = this.commandArgs.indexOf("--dry-run");
    if (~dryIndex) {
      this.commandArgs.splice(dryIndex, 1);
    }
  }
}

link.prototype.parsePrompt = function() {
  if (this.wet) {
    return clc.red("This is for real:\nrsync " + this.commandArgs.join(" ") + "\n") + "Execute command? : [NO/yes]";
  }
  return clc.yellow("Dry run:\nrsync " + this.commandArgs.join(" ") + "\n") + "Execute command? : [no/YES]";
}


link.prototype.stdout = function(data) {
  if (~data.toString().indexOf(" files...")) {
    if (!this.countingFiles) {
      waiting.start("Counting files...");
      this.countingFiles = true;
    }
  } else {
    if (this.countingFiles) {
      waiting.stop("Done");
      this.countingFiles = false;
    }
    console.log(data.toString().replace("\n",""));
  }
}

link.prototype.stderr = function(data) {
  console.log(data.toString().replace("\n",""));
}

link.prototype.onExit = function(code) {
  if (code !== 0) {
    return console.log('child process exited with code ' + code);
  } else if (!this.wet) {
    console.log(clc.yellow("Dry run complete.\n"));
    this.wet = true;
    this.promptForExecution();
  } else {
    console.log(clc.green("Execution complete!\n"));
    linksData.updateCompleteById(this.data.id);
  }
}
////////////////////////////////////////////////////////////////////////////////

function isAnswerPositive(input, wet) {
  return (wet && input.toLowerCase() == "yes") || (!wet &&  !~["n","no"].indexOf(input.toLowerCase()));
}




<commit_msg>set any answer not in ["","y","yes"] to prevent dry-run from running<commit_after>"use strict";

var clc = require('cli-color');
var read = require('read')
var spawn = require('child_process').spawn;
var rek = require('rekuire');

var linksDataUtils = rek('linksDataUtils');
var waiting = rek('waiting');
var linksData = rek('linksData');

module.exports = {
  link: link
};

function link(linkData) {
  this.data = linkData;
}

link.prototype.run = function(wet) {
  if (!linksDataUtils.varify(this.data)) {
    return console.log(clc.red("Link invalid! \nMaybe you forgot to connect a drive or to mount a file system?"));
  }
  this.wet = wet;
  this.promptForExecution();
}

////////////////////////////////////////////////////////////////////////////////

link.prototype.promptForExecution = function() {
  this.parseCommandArgs();
  read({prompt: this.parsePrompt()}, function(error, input, isDefault) {
    if (error) {
      return console.log(clc.red("Error handling input, or input invalid!"));
    } else if (isAnswerPositive(input, this.wet)) {
      this.execute();
    }
  }.bind(this));
}

link.prototype.execute = function() {
  var command = spawn('rsync', this.commandArgs);
  command.stdout.on('data', this.stdout.bind(this));
  command.stderr.on('data', this.stderr.bind(this));
  command.on('exit', this.onExit.bind(this));
}

link.prototype.parseCommandArgs = function() {
  this.commandArgs = [this.data.source, this.data.target, "-Phavyx", "--delete-after", "--dry-run"];
  if (this.wet) {
    var dryIndex = this.commandArgs.indexOf("--dry-run");
    if (~dryIndex) {
      this.commandArgs.splice(dryIndex, 1);
    }
  }
}

link.prototype.parsePrompt = function() {
  if (this.wet) {
    return clc.red("This is for real:\nrsync " + this.commandArgs.join(" ") + "\n") + "Execute command? : [NO/yes]";
  }
  return clc.yellow("Dry run:\nrsync " + this.commandArgs.join(" ") + "\n") + "Execute command? : [no/YES]";
}


link.prototype.stdout = function(data) {
  if (~data.toString().indexOf(" files...")) {
    if (!this.countingFiles) {
      waiting.start("Counting files...");
      this.countingFiles = true;
    }
  } else {
    if (this.countingFiles) {
      waiting.stop("Done");
      this.countingFiles = false;
    }
    console.log(data.toString().replace("\n",""));
  }
}

link.prototype.stderr = function(data) {
  console.log(data.toString().replace("\n",""));
}

link.prototype.onExit = function(code) {
  if (code !== 0) {
    return console.log('child process exited with code ' + code);
  } else if (!this.wet) {
    console.log(clc.yellow("Dry run complete.\n"));
    this.wet = true;
    this.promptForExecution();
  } else {
    console.log(clc.green("Execution complete!\n"));
    linksData.updateCompleteById(this.data.id);
  }
}
////////////////////////////////////////////////////////////////////////////////

function isAnswerPositive(input, wet) {
  return (wet && input.toLowerCase() == "yes") || (!wet &&  ~["","y","yes"].indexOf(input.toLowerCase()));
}





{'fraction_non_alphanumeric': 0.23307640750670242, 'fraction_numerical': 0.0006702412868632708, 'mean_word_length': 2.9582228116710874, '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': '1507954', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1924, 'n_words': 374}