mirror of
https://github.com/embarklabs/embark.git
synced 2025-01-12 23:05:07 +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) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
matches: ["token"],
|
||||||
match: () => cmd === "token",
|
description: __("Copies and prints the token for the cockpit"),
|
||||||
process: (callback) => {
|
process: (cmd, callback) => {
|
||||||
utils.copyToClipboard(this.authToken);
|
utils.copyToClipboard(this.authToken);
|
||||||
callback(null, __('Token copied to clipboard: %s', this.authToken));
|
callback(null, __('Token copied to clipboard: %s', this.authToken));
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,19 +49,17 @@ class BlockchainModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerConsoleCommands() {
|
registerConsoleCommands() {
|
||||||
const self = this;
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log blockchain on'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log blockchain on',
|
this.events.request('logs:ethereum:turnOn', callback);
|
||||||
process: (cb) => self.events.request('logs:ethereum:turnOn', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log blockchain off'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log blockchain off',
|
this.events.request('logs:ethereum:turnOff', callback);
|
||||||
process: (cb) => self.events.request('logs:ethereum:turnOff', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,20 +89,11 @@ class Console {
|
|||||||
__("possible commands are:"),
|
__("possible commands are:"),
|
||||||
// TODO: only if the blockchain is actually active!
|
// TODO: only if the blockchain is actually active!
|
||||||
// will need to pass te current embark state here
|
// will need to pass te current embark state here
|
||||||
"ipfs - " + __("instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"),
|
"ipfs".cyan + " - " + __("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)"),
|
"swarm".cyan + " - " + __("instantiated swarm-api object configured to the current environment (available if swarm is enabled)"),
|
||||||
"web3 - " + __("instantiated web3.js object configured to the current environment"),
|
"web3".cyan + " - " + __("instantiated web3.js object configured to the current environment"),
|
||||||
"EmbarkJS - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."),
|
"EmbarkJS".cyan + " - " + __("EmbarkJS static functions for Storage, Messages, Names, etc."),
|
||||||
"token - " + __("Copies and prints the token for the cockpit"),
|
"log <process> on/off".cyan + " - " + __("Activate or deactivate the logs of a sub-process. Options: blockchain, ipfs, webserver"),
|
||||||
"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"),
|
|
||||||
];
|
];
|
||||||
helpDescriptions.forEach((helpDescription) => {
|
helpDescriptions.forEach((helpDescription) => {
|
||||||
let matches = [] as string[];
|
let matches = [] as string[];
|
||||||
|
@ -217,22 +217,25 @@ class TransactionDebugger {
|
|||||||
this.cmdDebugger = false;
|
this.cmdDebugger = false;
|
||||||
this.currentCmdTxHash = "";
|
this.currentCmdTxHash = "";
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
const cmdName = cmd.split(" ")[0];
|
description: __("Debug the last transaction or the transaction specified by a hash"),
|
||||||
const txHash = cmd.split(" ")[1];
|
matches: (cmd: string) => {
|
||||||
return {
|
const [cmdName] = cmd.split(" ");
|
||||||
match: () => cmdName === "debug",
|
return cmdName === "debug";
|
||||||
process: (cb: any) => {
|
},
|
||||||
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
|
const [_cmdName, txHash] = cmd.split(" ");
|
||||||
if (txHash) {
|
if (txHash) {
|
||||||
this.embark.events.request("contracts:contract:byTxHash", txHash, (err: any, contract: any) => {
|
this.embark.events.request("contracts:contract:byTxHash", txHash, (err: any, contract: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.embark.logger.error(err);
|
this.embark.logger.error(err);
|
||||||
return;
|
return callback();
|
||||||
}
|
}
|
||||||
this.currentCmdTxHash = txHash;
|
this.currentCmdTxHash = txHash;
|
||||||
this.embark.logger.info("debugging tx " + txHash);
|
this.embark.logger.info("debugging tx " + txHash);
|
||||||
this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => {
|
this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => {
|
||||||
this.displayStepInfo();
|
this.displayStepInfo();
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -242,44 +245,45 @@ class TransactionDebugger {
|
|||||||
this.embark.logger.info("debugging tx " + this.lastTx);
|
this.embark.logger.info("debugging tx " + this.lastTx);
|
||||||
this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => {
|
this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => {
|
||||||
this.displayStepInfo();
|
this.displayStepInfo();
|
||||||
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
usage: "debug <txHash>",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("During a debug, step over forward"),
|
||||||
match: () => (cmd === "next" || cmd === "n"),
|
matches: ["next", "n"],
|
||||||
process: (cb: any) => {
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
if (!this.cmdDebugger) {
|
if (!this.cmdDebugger) {
|
||||||
this.embark.logger.warn(NO_DEBUG_SESSION);
|
this.embark.logger.warn(NO_DEBUG_SESSION);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
if (!this.cmdDebugger.canGoNext()) {
|
if (!this.cmdDebugger.canGoNext()) {
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
if (!this.cmdDebugger.currentStep()) {
|
if (!this.cmdDebugger.currentStep()) {
|
||||||
this.embark.logger.info("end of execution reached");
|
this.embark.logger.info("end of execution reached");
|
||||||
this.cmdDebugger.unload();
|
this.cmdDebugger.unload();
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
this.cmdDebugger.stepOverForward(true);
|
this.cmdDebugger.stepOverForward(true);
|
||||||
this.displayStepInfo();
|
this.displayStepInfo();
|
||||||
cb();
|
callback();
|
||||||
},
|
},
|
||||||
};
|
usage: " next/n",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("During a debug, step over back"),
|
||||||
match: () => (cmd === "previous" || cmd === "p"),
|
matches: ["previous", "p"],
|
||||||
process: (cb: any) => {
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
if (!this.cmdDebugger) {
|
if (!this.cmdDebugger) {
|
||||||
this.embark.logger.warn(NO_DEBUG_SESSION);
|
this.embark.logger.warn(NO_DEBUG_SESSION);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
if (!this.cmdDebugger.canGoPrevious()) {
|
if (!this.cmdDebugger.canGoPrevious()) {
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
if (!this.cmdDebugger.currentStep()) {
|
if (!this.cmdDebugger.currentStep()) {
|
||||||
this.embark.logger.info("end of execution reached");
|
this.embark.logger.info("end of execution reached");
|
||||||
@ -287,57 +291,57 @@ class TransactionDebugger {
|
|||||||
}
|
}
|
||||||
this.cmdDebugger.stepOverBack(true);
|
this.cmdDebugger.stepOverBack(true);
|
||||||
this.displayStepInfo();
|
this.displayStepInfo();
|
||||||
cb();
|
callback();
|
||||||
},
|
},
|
||||||
};
|
usage: " previous/p",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("During a debug, display local variables"),
|
||||||
match: () => (cmd === "var local" || cmd === "v l" || cmd === "vl"),
|
matches: ["var local", "v l", "vl"],
|
||||||
process: (cb: any) => {
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
if (!this.cmdDebugger) {
|
if (!this.cmdDebugger) {
|
||||||
this.embark.logger.warn(NO_DEBUG_SESSION);
|
this.embark.logger.warn(NO_DEBUG_SESSION);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
this.cmdDebugger.displayLocals();
|
this.cmdDebugger.displayLocals();
|
||||||
cb();
|
callback();
|
||||||
},
|
},
|
||||||
};
|
usage: " var local/v l/vl",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("During a debug, display global variables"),
|
||||||
match: () => (cmd === "var global" || cmd === "v g" || cmd === "vg"),
|
matches: ["var global", "v g", "vg"],
|
||||||
process: (cb: any) => {
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
if (!this.cmdDebugger) {
|
if (!this.cmdDebugger) {
|
||||||
this.embark.logger.warn(NO_DEBUG_SESSION);
|
this.embark.logger.warn(NO_DEBUG_SESSION);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
this.cmdDebugger.displayGlobals();
|
this.cmdDebugger.displayGlobals();
|
||||||
cb();
|
callback();
|
||||||
},
|
},
|
||||||
};
|
usage: " var global/v g/vg",
|
||||||
});
|
});
|
||||||
|
|
||||||
this.embark.registerConsoleCommand((cmd: string, options: any) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("During a debug, display all variables"),
|
||||||
match: () => (cmd === "var all" || cmd === "v a" || cmd === "va"),
|
matches: ["var all", "v a", "va"],
|
||||||
process: (cb: any) => {
|
process: (cmd: string, callback: (err?: string|object, output?: string) => void) => {
|
||||||
if (!this.cmdDebugger) {
|
if (!this.cmdDebugger) {
|
||||||
this.embark.logger.warn(NO_DEBUG_SESSION);
|
this.embark.logger.warn(NO_DEBUG_SESSION);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
this.getGlobals(this.currentCmdTxHash, (err: any, globals: any) => {
|
this.getGlobals(this.currentCmdTxHash, (err: any, globals: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
this.embark.logger.error(err);
|
this.embark.logger.error(err);
|
||||||
return cb();
|
return callback();
|
||||||
}
|
}
|
||||||
this.embark.logger.info(globals);
|
this.embark.logger.info(globals);
|
||||||
cb();
|
callback();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
usage: " var all/v a/va",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,19 +154,17 @@ class IPFS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerConsoleCommands() {
|
registerConsoleCommands() {
|
||||||
const self = this;
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log ipfs on'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log ipfs on',
|
this.events.request('logs:ipfs:turnOn', callback);
|
||||||
process: (cb) => self.events.request('logs:ipfs:turnOn', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log ipfs off'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log ipfs off',
|
this.events.request('logs:ipfs:turnOff', callback);
|
||||||
process: (cb) => self.events.request('logs:ipfs:turnOff', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,14 +11,18 @@ class PluginCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerCommand() {
|
registerCommand() {
|
||||||
this.embark.registerConsoleCommand((cmd, _options) => {
|
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(' ');
|
let cmdArray = cmd.split(' ');
|
||||||
cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0);
|
cmdArray = cmdArray.filter(cmd => cmd.trim().length > 0);
|
||||||
let cmdName = cmdArray[0];
|
this.installPlugin(cmdArray, callback);
|
||||||
return {
|
}
|
||||||
match: () => cmdName === 'plugin',
|
|
||||||
process: this.installPlugin.bind(this, cmdArray)
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,31 +69,28 @@ class Profiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerConsoleCommand() {
|
registerConsoleCommand() {
|
||||||
const self = this;
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
description: "Outputs the function profile of a contract",
|
||||||
let cmdName = cmd.split(' ')[0];
|
usage: "profile <contractName>",
|
||||||
let contractName = cmd.split(' ')[1];
|
matches: (cmd) => {
|
||||||
|
const [cmdName] = cmd.split(' ');
|
||||||
return {
|
return cmdName === 'profile';
|
||||||
match: () => cmdName === 'profile',
|
},
|
||||||
process: (callback) => {
|
process: (cmd, callback) => {
|
||||||
|
const [_cmdName, contractName] = cmd.split(' ');
|
||||||
this.profile(contractName, callback);
|
this.profile(contractName, callback);
|
||||||
}
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
registerApi() {
|
registerApi() {
|
||||||
const self = this;
|
this.embark.registerAPICall(
|
||||||
|
|
||||||
let plugin = this.plugins.createPlugin('profiler', {});
|
|
||||||
plugin.registerAPICall(
|
|
||||||
'get',
|
'get',
|
||||||
'/embark-api/profiler/:contractName',
|
'/embark-api/profiler/:contractName',
|
||||||
(req, res) => {
|
(req, res) => {
|
||||||
let contractName = req.params.contractName;
|
let contractName = req.params.contractName;
|
||||||
|
|
||||||
self.profileJSON(contractName, (err, table) => {
|
this.profileJSON(contractName, (err, table) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return res.send({error: err.message});
|
return res.send({error: err.message});
|
||||||
}
|
}
|
||||||
|
@ -141,19 +141,17 @@ class Swarm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerConsoleCommands() {
|
registerConsoleCommands() {
|
||||||
const self = this;
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log swarm on'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log swarm on',
|
this.events.request('logs:swarm:turnOn', callback);
|
||||||
process: (cb) => self.events.request('logs:swarm:turnOn', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
matches: ['log swarm off'],
|
||||||
return {
|
process: (cmd, callback) => {
|
||||||
match: () => cmd === 'log swarm off',
|
this.events.request('logs:swarm:turnOff', callback);
|
||||||
process: (cb) => self.events.request('logs:swarm:turnOff', cb)
|
}
|
||||||
};
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,40 +125,42 @@ class WebServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
registerConsoleCommands() {
|
registerConsoleCommands() {
|
||||||
const self = this;
|
this.embark.registerConsoleCommand({
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
usage: "webserver start/stop",
|
||||||
return {
|
description: __("Start or stop the websever"),
|
||||||
match: () => cmd === 'webserver start',
|
matches: ['webserver start'],
|
||||||
process: (cb) => self.events.request('start-webserver', cb)
|
process: (cmd, callback) => {
|
||||||
};
|
this.events.request('start-webserver', callback);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
matches: ['webserver stop'],
|
||||||
match: () => cmd === 'webserver stop',
|
process: (cmd, callback) => {
|
||||||
process: (cb) => self.events.request('stop-webserver', cb)
|
this.events.request('stop-webserver', callback);
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
description: __("Open a browser window at the Dapp's url"),
|
||||||
match: () => cmd === 'browser open',
|
matches: ['browser open'],
|
||||||
process: (cb) => self.events.request('open-browser', cb)
|
process: (cmd, callback) => {
|
||||||
};
|
this.events.request('open-browser', callback);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
matches: ['log webserver on'],
|
||||||
match: () => cmd === 'log webserver on',
|
process: (cmd, callback) => {
|
||||||
process: (cb) => self.events.request('logs:webserver:turnOn', cb)
|
this.events.request('logs:webserver:turnOn', callback);
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.embark.registerConsoleCommand((cmd, _options) => {
|
this.embark.registerConsoleCommand({
|
||||||
return {
|
matches: ['log webserver off'],
|
||||||
match: () => cmd === 'log webserver off',
|
process: (cmd, callback) => {
|
||||||
process: (cb) => self.events.request('logs:webserver:turnOff', cb)
|
this.events.request('logs:webserver:turnOff', callback);
|
||||||
};
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,12 +28,12 @@ module.exports = function (embark) {
|
|||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
embark.registerConsoleCommand((cmd) => {
|
embark.registerConsoleCommand({
|
||||||
if (cmd === "hello") {
|
matches: ["hello"],
|
||||||
return "hello there!";
|
description: 'Says Hello',
|
||||||
|
process: (cmd, callback) => {
|
||||||
|
callback(null, 'Hello there');
|
||||||
}
|
}
|
||||||
// continue to embark or next plugin;
|
|
||||||
return false;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
embark.events.on("contractsDeployed", function() {
|
embark.events.on("contractsDeployed", function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user