mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-12 14:54:57 +00:00
refactor: change registerConsoleCommands to the new API
This commit is contained in:
parent
bbcfe9b1de
commit
a147e2706b
@ -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));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 <txHash> - " + __("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 <process> on/off - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, "),
|
||||
"plugin install <package> - " + __("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 <process> on/off".cyan + " - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, ipfs, webserver"),
|
||||
];
|
||||
helpDescriptions.forEach((helpDescription) => {
|
||||
let matches = [] as string[];
|
||||
|
@ -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 <txHash>",
|
||||
});
|
||||
|
||||
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",
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 <package>",
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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 <contractName>",
|
||||
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});
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user