take configuration options from config and command line arguments when running simulator

This commit is contained in:
Iuri Matias 2017-02-18 08:01:03 -05:00
parent e09e40e3ba
commit 566812696d
3 changed files with 32 additions and 4 deletions

View File

@ -103,13 +103,18 @@ Cmd.prototype.blockchain = function() {
}; };
Cmd.prototype.simulator = function() { Cmd.prototype.simulator = function() {
var self = this;
program program
.command('simulator') .command('simulator [environment]')
.description('run a fast ethereum rpc simulator') .description('run a fast ethereum rpc simulator')
.option('--testrpc', 'use testrpc as the rpc simulator [default]') .option('--testrpc', 'use testrpc as the rpc simulator [default]')
.action(function(options) { .option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
//console.log('TestRPC not found; Please install it with "npm install -g ethereumjs-testrpc'); .option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
exec('testrpc'); .action(function(env, options) {
self.Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json'
});
self.Embark.simulator({port: options.port, host: options.host});
}); });
}; };

View File

@ -25,6 +25,7 @@ var ServicesMonitor = require('./services.js');
var Console = require('./console.js'); var Console = require('./console.js');
var IPFS = require('./ipfs.js'); var IPFS = require('./ipfs.js');
var Swarm = require('./swarm.js'); var Swarm = require('./swarm.js');
var Simulator = require('./simulator.js');
var Embark = { var Embark = {
@ -337,6 +338,11 @@ var Embark = {
} }
}, },
simulator: function(options) {
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
simulator.run(options);
}
}; };
module.exports = Embark; module.exports = Embark;

17
lib/simulator.js Normal file
View File

@ -0,0 +1,17 @@
var Simulator = function(options) {
this.blockchainConfig = options.blockchainConfig;
};
Simulator.prototype.run = function(options) {
var cmds = [];
cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545));
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
cmds.push("-a " + (options.num || 10));
exec('testrpc ' + cmds.join(' '));
};
module.exports = Simulator;