From d32d5f50bd6a42cfe862aa35c9ed5b10d63b35db Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Wed, 13 Dec 2017 17:58:07 -0500 Subject: [PATCH] check if geth command exists and warn user if not --- lib/cmds/blockchain/blockchain.js | 15 ++++++++++++++- lib/cmds/blockchain/geth_commands.js | 5 ++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/cmds/blockchain/blockchain.js b/lib/cmds/blockchain/blockchain.js index d0b31fb85..70ff88006 100644 --- a/lib/cmds/blockchain/blockchain.js +++ b/lib/cmds/blockchain/blockchain.js @@ -50,12 +50,26 @@ Blockchain.prototype.run = function() { console.log(("Embark Blockchain Using: " + this.client.name.underline).magenta); console.log("===============================================================================".magenta); console.log("===============================================================================".magenta); + if (!this.isClientInstalled()) { + console.log(("could not find " + this.config.geth_bin + " command; is " + this.client.name + " installed or in the PATH?").green); + return; + } var address = this.initChainAndGetAddress(); this.client.mainCommand(address, function(cmd) { self.runCommand(cmd, {async: true}); }); }; +Blockchain.prototype.isClientInstalled = function() { + let versionCmd = this.client.determineVersion(); + let result = this.runCommand(versionCmd); + + if (result.output === undefined || result.output.indexOf("not found") >= 0) { + return false; + } + return true; +}; + Blockchain.prototype.initChainAndGetAddress = function() { var address = null, result; @@ -94,4 +108,3 @@ var BlockchainClient = function(blockchainConfig, client, env) { }; module.exports = BlockchainClient; - diff --git a/lib/cmds/blockchain/geth_commands.js b/lib/cmds/blockchain/geth_commands.js index 5d8104c35..9b04e0e4c 100644 --- a/lib/cmds/blockchain/geth_commands.js +++ b/lib/cmds/blockchain/geth_commands.js @@ -34,6 +34,10 @@ class GethCommands { return cmd; } + determineVersion() { + return this.geth_bin + " version"; + } + determineNetworkType(config) { let cmd = ""; if (config.networkType === 'testnet') { @@ -203,4 +207,3 @@ class GethCommands { } module.exports = GethCommands; -