<commit_before>
var cHelpers = require('./helpers'),
    gruntMod = require('grunt');

var PYTHON_BINARY = 'python';

// path to depswriter from closure lib path
var DEPSWRITER = '/closure/bin/build/depswriter.py';


var depsWriter = {};

/**
 * Perform validations for given options
 *
 * @return {boolean|Object} false if error
 */
depsWriter.validate = function validate( options )
{
  // ---
  // check depsExec existence
  // ---
  // check for closure lib path
  var libPath = options.closureLibraryPath,
      depsExec;
  if (!libPath) {
    // check for direct assignment of depswriter script
    depsExec = options.depswriter;
    if (!depsExec) {
      cHelpers.log.error('One of ' + 'closureLibraryPath'.red + ' or ' + 'depswriter'.red + ' properties are required');
      return false;
    }
  } else {
    depsExec = libPath + DEPSWRITER;
  }
  depsExec = gruntMod.template.process(depsExec);
  if (!gruntMod.file.isFile( depsExec )) {
    cHelpers.log.error('depswriter file/path not valid: ' + depsExec.red);
    return false;
  }

  return true;
};


/**
 * Prepare and compile the depswriter command we will execute
 *
 * @param  {Object} options The options.
 * @param  {Object} fileObj The (grunt) file object.
 * @return {string|boolean} boolean false if we failed, command string if all ok
 */
depsWriter.createCommand = function createCommand( options, fileObj ) {
  // get python binary
  var pythonBinary = options.pythonBinary || PYTHON_BINARY;
  var cmd = pythonBinary + ' ';

  // define the depsWriter executable
  var depsExec = options.depswriter || options.closureLibraryPath + DEPSWRITER;
  depsExec = gruntMod.template.process( depsExec );
  cmd += depsExec + ' ';
  //
  // Check for root, root_with_prefix and path_with_depspath options
  //
  var directives = ['root', 'root_with_prefix', 'path_with_depspath'],
      directive = directives.shift();
  while(directive) {
    if ( options.hasOwnProperty(directive) ) {
      cmd += cHelpers.makeParam( options[directive], '--' + directive + '=', true);
    }
    directive = directives.shift();
  }

  // ---
  // check if output file is defined
  // ---
  var dest = fileObj.dest;
  if (dest && dest.length) {
    gruntMod.file.write(dest, ''); // create the file if it's not there.
    cmd += ' --output_file=' + gruntMod.template.process(dest);
  }

  // ---
  // Check for file targets...
  // ---
  var files = gruntMod.file.expand(fileObj.src || {});
  for (var i = 0, len = files.length; i < len; i++) {
    cmd += ' ' + files[i];
  }

  return cmd;<commit_msg>Allow command line parameters to be included by target in addition to globally via the options object.<commit_after>
var cHelpers = require('./helpers'),
    gruntMod = require('grunt');

var PYTHON_BINARY = 'python';

// path to depswriter from closure lib path
var DEPSWRITER = '/closure/bin/build/depswriter.py';


var depsWriter = {};

/**
 * Perform validations for given options
 *
 * @return {boolean|Object} false if error
 */
depsWriter.validate = function validate( options )
{
  // ---
  // check depsExec existence
  // ---
  // check for closure lib path
  var libPath = options.closureLibraryPath,
      depsExec;
  if (!libPath) {
    // check for direct assignment of depswriter script
    depsExec = options.depswriter;
    if (!depsExec) {
      cHelpers.log.error('One of ' + 'closureLibraryPath'.red + ' or ' + 'depswriter'.red + ' properties are required');
      return false;
    }
  } else {
    depsExec = libPath + DEPSWRITER;
  }
  depsExec = gruntMod.template.process(depsExec);
  if (!gruntMod.file.isFile( depsExec )) {
    cHelpers.log.error('depswriter file/path not valid: ' + depsExec.red);
    return false;
  }

  return true;
};


/**
 * Prepare and compile the depswriter command we will execute
 *
 * @param  {Object} options The options.
 * @param  {Object} fileObj The (grunt) file object.
 * @return {string|boolean} boolean false if we failed, command string if all ok
 */
depsWriter.createCommand = function createCommand( options, fileObj ) {
  // get python binary
  var pythonBinary = options.pythonBinary || PYTHON_BINARY;
  var cmd = pythonBinary + ' ';

  // define the depsWriter executable
  var depsExec = options.depswriter || options.closureLibraryPath + DEPSWRITER;
  depsExec = gruntMod.template.process( depsExec );
  cmd += depsExec + ' ';
  //
  // Check for root, root_with_prefix and path_with_depspath options
  //
  var directives = ['root', 'root_with_prefix', 'path_with_depspath'],
      directive = directives.shift();
  while(directive) {
    // check if the global options has a definition for this
    // parameter type
    if ( options.hasOwnProperty(directive) ) {
      cmd += cHelpers.makeParam( options[directive], '--' + directive + '=', true);
    }

    // check if the target has a definition for this parameter type
    if( fileObj.hasOwnProperty( directive ) ) {
      cmd += cHelpers.makeParam( fileObj[directive], '--' + directive + '=', true);
    }

    directive = directives.shift();
  }

  // ---
  // check if output file is defined
  // ---
  var dest = fileObj.dest;
  if (dest && dest.length) {
    gruntMod.file.write(dest, ''); // create the file if it's not there.
    cmd += ' --output_file=' + gruntMod.template.process(dest);
  }

  // ---
  // Check for file targets...
  // ---
  var files = gruntMod.file.expand(fileObj.src || {});
  for (var i = 0, len = files.length; i < len; i++) {
    cmd += ' ' + files[i];
  }

  return cmd;
{'fraction_non_alphanumeric': 0.13762304046664237, 'fraction_numerical': 0.0003645643456069996, 'mean_word_length': 3.0138990490124358, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5483331', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1751, 'n_words': 480}