diff --git a/src/lib/modules/authenticator/index.js b/src/lib/modules/authenticator/index.js index 504aae5b2..9f3352c64 100644 --- a/src/lib/modules/authenticator/index.js +++ b/src/lib/modules/authenticator/index.js @@ -70,14 +70,13 @@ class Authenticator { } ); - this.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === "token", - process: (callback) => { - utils.copyToClipboard(this.authToken); - callback(null, __('Token copied to clipboard: %s', this.authToken)); - } - }; + this.embark.registerConsoleCommand({ + matches: ["token"], + description: __("Copies and prints the token for the cockpit"), + process: (cmd, callback) => { + utils.copyToClipboard(this.authToken); + callback(null, __('Token copied to clipboard: %s', this.authToken)); + } }); } diff --git a/src/lib/modules/blockchain_process/index.js b/src/lib/modules/blockchain_process/index.js index 87409e28f..2dcbc602a 100644 --- a/src/lib/modules/blockchain_process/index.js +++ b/src/lib/modules/blockchain_process/index.js @@ -49,19 +49,17 @@ class BlockchainModule { } registerConsoleCommands() { - const self = this; - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log blockchain on', - process: (cb) => self.events.request('logs:ethereum:turnOn', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log blockchain on'], + process: (cmd, callback) => { + this.events.request('logs:ethereum:turnOn', callback); + } }); - - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log blockchain off', - process: (cb) => self.events.request('logs:ethereum:turnOff', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log blockchain off'], + process: (cmd, callback) => { + this.events.request('logs:ethereum:turnOff', callback); + } }); } diff --git a/src/lib/modules/console/index.ts b/src/lib/modules/console/index.ts index c7fe8c618..c94f8497e 100644 --- a/src/lib/modules/console/index.ts +++ b/src/lib/modules/console/index.ts @@ -89,20 +89,11 @@ class Console { __("possible commands are:"), // TODO: only if the blockchain is actually active! // will need to pass te current embark state here - "ipfs - " + __("instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"), - "swarm - " + __("instantiated swarm-api object configured to the current environment (available if swarm is enabled)"), - "web3 - " + __("instantiated web3.js object configured to the current environment"), - "EmbarkJS - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."), - "token - " + __("Copies and prints the token for the cockpit"), - "debug - " + __("Debug the last transaction or the transaction specified by a hash"), - " next/n - " + __("During a debug, step over forward"), - " previous/p - " + __("During a debug, step over back"), - " var local/v l/vl - " + __("During a debug, display local variables"), - " var global/v g/vg - " + __("During a debug, display global variables"), - " var all/v a/va - " + __("During a debug, display all variables"), - " var all/v a/va - " + __("During a debug, display all variables"), - "log on/off - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, "), - "plugin install - " + __("Installs a plugin in the Dapp. eg: plugin install embark-solc"), + "ipfs".cyan + " - " + __("instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"), + "swarm".cyan + " - " + __("instantiated swarm-api object configured to the current environment (available if swarm is enabled)"), + "web3".cyan + " - " + __("instantiated web3.js object configured to the current environment"), + "EmbarkJS".cyan + " - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."), + "log on/off".cyan + " - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, ipfs, webserver"), ]; helpDescriptions.forEach((helpDescription) => { let matches = [] as string[]; diff --git a/src/lib/modules/debugger/index.ts b/src/lib/modules/debugger/index.ts index d89d47396..bf68f527d 100644 --- a/src/lib/modules/debugger/index.ts +++ b/src/lib/modules/debugger/index.ts @@ -217,127 +217,131 @@ class TransactionDebugger { this.cmdDebugger = false; this.currentCmdTxHash = ""; - this.embark.registerConsoleCommand((cmd: string, options: any) => { - const cmdName = cmd.split(" ")[0]; - const txHash = cmd.split(" ")[1]; - return { - match: () => cmdName === "debug", - process: (cb: any) => { - if (txHash) { - this.embark.events.request("contracts:contract:byTxHash", txHash, (err: any, contract: any) => { - if (err) { - this.embark.logger.error(err); - return; - } - this.currentCmdTxHash = txHash; - this.embark.logger.info("debugging tx " + txHash); - this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => { - this.displayStepInfo(); - }); - }); - return; - } - this.currentCmdTxHash = this.lastTx; - const filename: string = this.txTracker[this.lastTx].contract.filename; - this.embark.logger.info("debugging tx " + this.lastTx); - this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => { - this.displayStepInfo(); - }); - }, - }; - }); - - this.embark.registerConsoleCommand((cmd: string, options: any) => { - return { - match: () => (cmd === "next" || cmd === "n"), - process: (cb: any) => { - if (!this.cmdDebugger) { - this.embark.logger.warn(NO_DEBUG_SESSION); - return cb(); - } - if (!this.cmdDebugger.canGoNext()) { - return cb(); - } - if (!this.cmdDebugger.currentStep()) { - this.embark.logger.info("end of execution reached"); - this.cmdDebugger.unload(); - return cb(); - } - this.cmdDebugger.stepOverForward(true); - this.displayStepInfo(); - cb(); - }, - }; - }); - - this.embark.registerConsoleCommand((cmd: string, options: any) => { - return { - match: () => (cmd === "previous" || cmd === "p"), - process: (cb: any) => { - if (!this.cmdDebugger) { - this.embark.logger.warn(NO_DEBUG_SESSION); - return cb(); - } - if (!this.cmdDebugger.canGoPrevious()) { - return cb(); - } - if (!this.cmdDebugger.currentStep()) { - this.embark.logger.info("end of execution reached"); - return this.cmdDebugger.unload(); - } - this.cmdDebugger.stepOverBack(true); - this.displayStepInfo(); - cb(); - }, - }; - }); - - this.embark.registerConsoleCommand((cmd: string, options: any) => { - return { - match: () => (cmd === "var local" || cmd === "v l" || cmd === "vl"), - process: (cb: any) => { - if (!this.cmdDebugger) { - this.embark.logger.warn(NO_DEBUG_SESSION); - return cb(); - } - this.cmdDebugger.displayLocals(); - cb(); - }, - }; - }); - - this.embark.registerConsoleCommand((cmd: string, options: any) => { - return { - match: () => (cmd === "var global" || cmd === "v g" || cmd === "vg"), - process: (cb: any) => { - if (!this.cmdDebugger) { - this.embark.logger.warn(NO_DEBUG_SESSION); - return cb(); - } - this.cmdDebugger.displayGlobals(); - cb(); - }, - }; - }); - - this.embark.registerConsoleCommand((cmd: string, options: any) => { - return { - match: () => (cmd === "var all" || cmd === "v a" || cmd === "va"), - process: (cb: any) => { - if (!this.cmdDebugger) { - this.embark.logger.warn(NO_DEBUG_SESSION); - return cb(); - } - this.getGlobals(this.currentCmdTxHash, (err: any, globals: any) => { + this.embark.registerConsoleCommand({ + description: __("Debug the last transaction or the transaction specified by a hash"), + matches: (cmd: string) => { + const [cmdName] = cmd.split(" "); + return cmdName === "debug"; + }, + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + const [_cmdName, txHash] = cmd.split(" "); + if (txHash) { + this.embark.events.request("contracts:contract:byTxHash", txHash, (err: any, contract: any) => { if (err) { this.embark.logger.error(err); - return cb(); + return callback(); } - this.embark.logger.info(globals); - cb(); + this.currentCmdTxHash = txHash; + this.embark.logger.info("debugging tx " + txHash); + this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => { + this.displayStepInfo(); + callback(); + }); }); - }, - }; + return; + } + this.currentCmdTxHash = this.lastTx; + const filename: string = this.txTracker[this.lastTx].contract.filename; + this.embark.logger.info("debugging tx " + this.lastTx); + this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => { + this.displayStepInfo(); + callback(); + }); + }, + usage: "debug ", + }); + + this.embark.registerConsoleCommand({ + description: __("During a debug, step over forward"), + matches: ["next", "n"], + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + if (!this.cmdDebugger) { + this.embark.logger.warn(NO_DEBUG_SESSION); + return callback(); + } + if (!this.cmdDebugger.canGoNext()) { + return callback(); + } + if (!this.cmdDebugger.currentStep()) { + this.embark.logger.info("end of execution reached"); + this.cmdDebugger.unload(); + return callback(); + } + this.cmdDebugger.stepOverForward(true); + this.displayStepInfo(); + callback(); + }, + usage: " next/n", + }); + + this.embark.registerConsoleCommand({ + description: __("During a debug, step over back"), + matches: ["previous", "p"], + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + if (!this.cmdDebugger) { + this.embark.logger.warn(NO_DEBUG_SESSION); + return callback(); + } + if (!this.cmdDebugger.canGoPrevious()) { + return callback(); + } + if (!this.cmdDebugger.currentStep()) { + this.embark.logger.info("end of execution reached"); + return this.cmdDebugger.unload(); + } + this.cmdDebugger.stepOverBack(true); + this.displayStepInfo(); + callback(); + }, + usage: " previous/p", + }); + + this.embark.registerConsoleCommand({ + description: __("During a debug, display local variables"), + matches: ["var local", "v l", "vl"], + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + if (!this.cmdDebugger) { + this.embark.logger.warn(NO_DEBUG_SESSION); + return callback(); + } + this.cmdDebugger.displayLocals(); + callback(); + }, + usage: " var local/v l/vl", + }); + + this.embark.registerConsoleCommand({ + description: __("During a debug, display global variables"), + matches: ["var global", "v g", "vg"], + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + if (!this.cmdDebugger) { + this.embark.logger.warn(NO_DEBUG_SESSION); + return callback(); + } + this.cmdDebugger.displayGlobals(); + callback(); + }, + usage: " var global/v g/vg", + }); + + this.embark.registerConsoleCommand({ + description: __("During a debug, display all variables"), + matches: ["var all", "v a", "va"], + process: (cmd: string, callback: (err?: string|object, output?: string) => void) => { + if (!this.cmdDebugger) { + this.embark.logger.warn(NO_DEBUG_SESSION); + return callback(); + } + this.getGlobals(this.currentCmdTxHash, (err: any, globals: any) => { + if (err) { + this.embark.logger.error(err); + return callback(); + } + this.embark.logger.info(globals); + callback(); + }); + }, + usage: " var all/v a/va", }); } diff --git a/src/lib/modules/ipfs/index.js b/src/lib/modules/ipfs/index.js index 8e483c317..5955f2bbe 100644 --- a/src/lib/modules/ipfs/index.js +++ b/src/lib/modules/ipfs/index.js @@ -154,19 +154,17 @@ class IPFS { } registerConsoleCommands() { - const self = this; - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log ipfs on', - process: (cb) => self.events.request('logs:ipfs:turnOn', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log ipfs on'], + process: (cmd, callback) => { + this.events.request('logs:ipfs:turnOn', callback); + } }); - - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log ipfs off', - process: (cb) => self.events.request('logs:ipfs:turnOff', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log ipfs off'], + process: (cmd, callback) => { + this.events.request('logs:ipfs:turnOff', callback); + } }); } diff --git a/src/lib/modules/plugin_cmd/index.js b/src/lib/modules/plugin_cmd/index.js index fdbc64783..84d27e8ac 100644 --- a/src/lib/modules/plugin_cmd/index.js +++ b/src/lib/modules/plugin_cmd/index.js @@ -11,14 +11,18 @@ class PluginCommand { } registerCommand() { - this.embark.registerConsoleCommand((cmd, _options) => { - let cmdArray = cmd.split(' '); - cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0); - let cmdName = cmdArray[0]; - return { - match: () => cmdName === 'plugin', - process: this.installPlugin.bind(this, cmdArray) - }; + this.embark.registerConsoleCommand({ + description: "Installs a plugin in the Dapp. eg: plugin install embark-solc", + usage: "plugin install ", + matches: (cmd) => { + const [cmdName] = cmd.split(' '); + return cmdName === 'plugin'; + }, + process: (cmd, callback) => { + let cmdArray = cmd.split(' '); + cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0); + this.installPlugin(cmdArray, callback); + } }); } diff --git a/src/lib/modules/profiler/index.js b/src/lib/modules/profiler/index.js index 7f1a64375..8601fa313 100644 --- a/src/lib/modules/profiler/index.js +++ b/src/lib/modules/profiler/index.js @@ -69,31 +69,28 @@ class Profiler { } registerConsoleCommand() { - const self = this; - self.embark.registerConsoleCommand((cmd, _options) => { - let cmdName = cmd.split(' ')[0]; - let contractName = cmd.split(' ')[1]; - - return { - match: () => cmdName === 'profile', - process: (callback) => { - this.profile(contractName, callback); - } - }; + this.embark.registerConsoleCommand({ + description: "Outputs the function profile of a contract", + usage: "profile ", + matches: (cmd) => { + const [cmdName] = cmd.split(' '); + return cmdName === 'profile'; + }, + process: (cmd, callback) => { + const [_cmdName, contractName] = cmd.split(' '); + this.profile(contractName, callback); + } }); } registerApi() { - const self = this; - - let plugin = this.plugins.createPlugin('profiler', {}); - plugin.registerAPICall( + this.embark.registerAPICall( 'get', '/embark-api/profiler/:contractName', (req, res) => { let contractName = req.params.contractName; - self.profileJSON(contractName, (err, table) => { + this.profileJSON(contractName, (err, table) => { if (err) { return res.send({error: err.message}); } diff --git a/src/lib/modules/swarm/index.js b/src/lib/modules/swarm/index.js index 21a0bfa23..8b5a73235 100644 --- a/src/lib/modules/swarm/index.js +++ b/src/lib/modules/swarm/index.js @@ -141,19 +141,17 @@ class Swarm { } registerConsoleCommands() { - const self = this; - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log swarm on', - process: (cb) => self.events.request('logs:swarm:turnOn', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log swarm on'], + process: (cmd, callback) => { + this.events.request('logs:swarm:turnOn', callback); + } }); - - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log swarm off', - process: (cb) => self.events.request('logs:swarm:turnOff', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log swarm off'], + process: (cmd, callback) => { + this.events.request('logs:swarm:turnOff', callback); + } }); } diff --git a/src/lib/modules/webserver/index.js b/src/lib/modules/webserver/index.js index cd1a586a6..83d914b8f 100644 --- a/src/lib/modules/webserver/index.js +++ b/src/lib/modules/webserver/index.js @@ -125,40 +125,42 @@ class WebServer { } registerConsoleCommands() { - const self = this; - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'webserver start', - process: (cb) => self.events.request('start-webserver', cb) - }; + this.embark.registerConsoleCommand({ + usage: "webserver start/stop", + description: __("Start or stop the websever"), + matches: ['webserver start'], + process: (cmd, callback) => { + this.events.request('start-webserver', callback); + } }); - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'webserver stop', - process: (cb) => self.events.request('stop-webserver', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['webserver stop'], + process: (cmd, callback) => { + this.events.request('stop-webserver', callback); + } }); - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'browser open', - process: (cb) => self.events.request('open-browser', cb) - }; + this.embark.registerConsoleCommand({ + description: __("Open a browser window at the Dapp's url"), + matches: ['browser open'], + process: (cmd, callback) => { + this.events.request('open-browser', callback); + } }); - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log webserver on', - process: (cb) => self.events.request('logs:webserver:turnOn', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log webserver on'], + process: (cmd, callback) => { + this.events.request('logs:webserver:turnOn', callback); + } }); - self.embark.registerConsoleCommand((cmd, _options) => { - return { - match: () => cmd === 'log webserver off', - process: (cb) => self.events.request('logs:webserver:turnOff', cb) - }; + this.embark.registerConsoleCommand({ + matches: ['log webserver off'], + process: (cmd, callback) => { + this.events.request('logs:webserver:turnOff', callback); + } }); } diff --git a/test_apps/test_app/extensions/embark-service/index.js b/test_apps/test_app/extensions/embark-service/index.js index e006f9b0e..a35761904 100644 --- a/test_apps/test_app/extensions/embark-service/index.js +++ b/test_apps/test_app/extensions/embark-service/index.js @@ -28,12 +28,12 @@ module.exports = function (embark) { cb(); }); - embark.registerConsoleCommand((cmd) => { - if (cmd === "hello") { - return "hello there!"; + embark.registerConsoleCommand({ + matches: ["hello"], + description: 'Says Hello', + process: (cmd, callback) => { + callback(null, 'Hello there'); } - // continue to embark or next plugin; - return false; }); embark.events.on("contractsDeployed", function() {