<commit_before>'use strict';
var inquirer = require('inquirer');
var chalk = require('chalk');
var async = require('async');
var SDK = require('flowxo-sdk');
var chai = require('chai');
chai.use(SDK.Chai);
var RunUtil = {};

RunUtil.header = function(grunt, msg, color) {
  msg = color ? chalk[color](msg) : msg;
  var line = Array(msg.length + 1).join('-');
  line = color ? chalk[color](line) : line;

  grunt.log.subhead(msg);
  grunt.log.writeln(line);
};

RunUtil.displayScriptData = function(grunt, data) {
  RunUtil.header(grunt,'DATA:','green');
  grunt.log.writeln(chalk.cyan(JSON.stringify(data, null, 2)));

};

RunUtil.displayScriptOutput = function(grunt,method,data){
  // First create an indexed hash of fields
  var fieldsIdx = method.fields.output.reduce(function(data,f){
    data[f.key] = f;
    return data;
  },{});

  // Now go through the output and create a labeled version
  var dataLabelled = Object.keys(data).reduce(function(memo,key){
    memo[fieldsIdx[key].label] = data[key];
    return memo;
  },{});

  RunUtil.header(grunt,'OUTPUT:','green');
  grunt.log.writeln(chalk.cyan(JSON.stringify(dataLabelled, null, 2)));
};

RunUtil.promptMethod = function(service, cb) {
  var prompts = [{
    type: 'list',
    name: 'method',
    message: 'Method',
    choices: service.methods.map(function(m) {
      return {
        name: m.name,
        value: m
      };
    })
  }];

  inquirer.prompt(prompts, function(result) {
    cb(null, result.method);<commit_msg>Handle case where a script has failed to define a field that we're trying to output<commit_after>'use strict';
var inquirer = require('inquirer');
var chalk = require('chalk');
var async = require('async');
var SDK = require('flowxo-sdk');
var chai = require('chai');
chai.use(SDK.Chai);
var RunUtil = {};

RunUtil.header = function(grunt, msg, color) {
  msg = color ? chalk[color](msg) : msg;
  var line = Array(msg.length + 1).join('-');
  line = color ? chalk[color](line) : line;

  grunt.log.subhead(msg);
  grunt.log.writeln(line);
};

RunUtil.displayScriptData = function(grunt, data) {
  RunUtil.header(grunt,'DATA:','green');
  grunt.log.writeln(chalk.cyan(JSON.stringify(data, null, 2)));

};

RunUtil.displayScriptOutput = function(grunt,method,data){
  // First create an indexed hash of fields
  var fieldsIdx = method.fields.output.reduce(function(data,f){
    data[f.key] = f;
    return data;
  },{});

  // Now go through the output and create a labeled version
  var dataLabelled = Object.keys(data).reduce(function(memo,key){
    memo[fieldsIdx.hasOwnProperty(key) ? fieldsIdx[key].label : '??UNKNOWN??'] = data[key];
    return memo;
  },{});

  RunUtil.header(grunt,'OUTPUT:','green');
  grunt.log.writeln(chalk.cyan(JSON.stringify(dataLabelled, null, 2)));
};

RunUtil.promptMethod = function(service, cb) {
  var prompts = [{
    type: 'list',
    name: 'method',
    message: 'Method',
    choices: service.methods.map(function(m) {
      return {
        name: m.name,
        value: m
      };
    })
  }];

  inquirer.prompt(prompts, function(result) {
    cb(null, result.method);
{'fraction_non_alphanumeric': 0.17161290322580644, 'fraction_numerical': 0.001935483870967742, 'mean_word_length': 4.042276422764227, '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': '1659745', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1061, 'n_words': 224}