<commit_before>var Compiler = require('codius-engine').Compiler;
var FileManager = require('codius-engine').FileManager;
var Engine = require('codius-engine').Engine;

var concat = require('concat-stream');

var RunCommand = function (codius) {
  this.codius = codius;
};

/**
 * Run a contract
 */
RunCommand.prototype.run = function () {
  var currentDir = process.cwd();

  var engineConfig = this.codius.config.getEngineConfig();

  var compiler = new Compiler(engineConfig);
  var fileManager = new FileManager(engineConfig);

  compiler.on('file', function (event) {
    fileManager.storeFileWithHash(event.hash, event.data);
  });

  var contractHash = compiler.compileModule(currentDir);
  console.log('Running contract '+contractHash);

  var engine = new Engine(engineConfig);

  process.stdin.pipe(concat(function (inputData) {
    if (!Buffer.isBuffer(inputData)) {
      inputData = new Buffer(0);
    }

    // TODO: inputData contains the stdin, do something with it

    engine.runContract(contractHash, function (error, result) {

    });
  }));
};

exports.RunCommand = RunCommand;<commit_msg>[FEATURE] Ability to pass data from a file or via stdin.<commit_after>var Compiler = require('codius-engine').Compiler;
var FileManager = require('codius-engine').FileManager;
var Engine = require('codius-engine').Engine;

var concat = require('concat-stream');
var fs = require('fs');

var RunCommand = function (codius) {
  this.codius = codius;
};

/**
 * Run a contract
 */
RunCommand.prototype.run = function () {
  var currentDir = process.cwd();

  var engineConfig = this.codius.config.getEngineConfig();

  var compiler = new Compiler(engineConfig);
  var fileManager = new FileManager(engineConfig);

  compiler.on('file', function (event) {
    fileManager.storeFileWithHash(event.hash, event.data);
  });

  var contractHash = compiler.compileModule(currentDir);
  console.log('Running contract '+contractHash);

  var engine = new Engine(engineConfig);

  // Read input data from stdin
  if (engineConfig.input === '-') {
    process.stdin.setEncoding('utf-8');
    process.stdin.pipe(concat(function (inputData) {
      runContract(inputData);
    }));

  // Read input data from a file
  } else if (engineConfig.input) {
    fs.readFile(engineConfig.input, 'utf-8', function (error, fileData) {
      if (error) {
        console.error(error);
        return;
      }

      runContract(fileData);
    });

  // No input data provided
  } else {
    runContract('');
  }

  function runContract(inputData) {
    engine.runContract(contractHash, inputData, function (error, result) {

    });
  }
};

exports.RunCommand = RunCommand;
{'fraction_non_alphanumeric': 0.1380737396538751, 'fraction_numerical': 0.001128668171557562, 'mean_word_length': 3.9887429643527206, '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': '4469462', 'n_tokens_mistral': 810, 'n_tokens_neox': 788, 'n_words': 183}