diff --git a/packages/embark-typings/src/embark.d.ts b/packages/embark-typings/src/embark.d.ts index edfa3c2d1..c78ce725f 100644 --- a/packages/embark-typings/src/embark.d.ts +++ b/packages/embark-typings/src/embark.d.ts @@ -1,4 +1,5 @@ import { Logger } from "./logger"; +import { Plugins } from "./plugins"; export interface Events { on: any; @@ -25,6 +26,7 @@ export interface Embark { solc: string; } }; + plugins: Plugins; reloadConfig(): void; }; registerActionForEvent(name: string, action: (callback: () => void) => void): void; diff --git a/packages/embark/src/lib/modules/console/index.ts b/packages/embark/src/lib/modules/console/index.ts index d1fbe134e..24b060689 100644 --- a/packages/embark/src/lib/modules/console/index.ts +++ b/packages/embark/src/lib/modules/console/index.ts @@ -118,7 +118,7 @@ class Console { "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"), + "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[]; @@ -139,6 +139,12 @@ class Console { } private executeCmd(cmd: string, callback: any) { + // if this is the embark console process, send the command to the process + // running all the needed services (ie the process running `embark run`) + if (this.isEmbarkConsole) { + return this.ipc.request("console:executeCmd", cmd, callback); + } + if (!(cmd.split(" ")[0] === "history" || cmd === __("history"))) { this.saveHistory(cmd); } @@ -180,12 +186,6 @@ class Console { return callback(null, output); } - // if this is the embark console process, send the command to the process - // running all the needed services (ie the process running `embark run`) - if (this.isEmbarkConsole) { - return this.ipc.request("console:executeCmd", cmd, callback); - } - this.events.request("runcode:eval", cmd, (err: Error, result: any) => { if (err) { return callback(err.message); @@ -242,7 +242,7 @@ class Console { const [_cmdName, length] = cmd.split(" "); this.getHistory(length, callback); }, - usage: "history ", + usage: "history [optionalLength]", }); } diff --git a/packages/embark/src/lib/modules/console/suggestions.ts b/packages/embark/src/lib/modules/console/suggestions.ts index b7d086760..b9317e762 100644 --- a/packages/embark/src/lib/modules/console/suggestions.ts +++ b/packages/embark/src/lib/modules/console/suggestions.ts @@ -52,6 +52,16 @@ export default class Suggestions { }); } + private formatMatches(matches: any): string { + if (Array.isArray(matches)) { + return matches.join(", "); + } + if (typeof matches === "function") { + return ""; + } + return matches || ""; + } + public getSuggestions(cmd: string, cb: (results: SuggestionsList) => any) { if (cmd === "") { return cb([]); } const suggestions: SuggestionsList = []; @@ -67,6 +77,10 @@ export default class Suggestions { suggestions.push({value: "profile " + contract.className, command_type: "embark command", description: "profile " + contract.className + " contract"}); }); + const plugins = this.embark.config.plugins.getPluginsProperty("console", "console"); + for (const plugin of plugins) { + suggestions.push({value: plugin.usage || this.formatMatches(plugin.matches), command_type: "plugin command", description: plugin.description}); + } suggestions.push({value: "help", command_type: "embark command", description: "displays quick list of some of the available embark commands"}); suggestions.push({value: "versions", command_type: "embark command", description: "display versions in use for libraries and tools like web3 and solc"}); suggestions.push({value: "ipfs", command_type: "javascript object", description: "instantiated js-ipfs object configured to the current environment (available if ipfs is enabled)"}); @@ -81,7 +95,7 @@ export default class Suggestions { try { const toRemove: string = "." + cmd.split(".").reverse()[0]; const cmdToSearch: string = cmd.replace((new RegExp(toRemove + "$")), ""); - return this.events.request("runcode:eval", "Object.keys(" + cmdToSearch + ")", (err: any, result: any) => { + return this.events.request("runcode:eval", "Object.getOwnPropertyNames(" + cmdToSearch + ")", (err: any, result: any) => { try { if (Array.isArray(result)) { result.forEach((match: string) => { diff --git a/packages/embark/src/lib/modules/debugger/index.ts b/packages/embark/src/lib/modules/debugger/index.ts index 2726cede7..0adf1d1d2 100644 --- a/packages/embark/src/lib/modules/debugger/index.ts +++ b/packages/embark/src/lib/modules/debugger/index.ts @@ -250,7 +250,7 @@ class TransactionDebugger { const filename: string = this.txTracker[this.lastTx].contract.filename; startDebug(txHash, filename, callback); }, - usage: "debug ", + usage: "debug [txHash]", }); this.embark.registerConsoleCommand({ diff --git a/packages/embark/src/lib/modules/ens/index.js b/packages/embark/src/lib/modules/ens/index.js index 60d9a7f02..960b343ca 100644 --- a/packages/embark/src/lib/modules/ens/index.js +++ b/packages/embark/src/lib/modules/ens/index.js @@ -91,7 +91,7 @@ class ENS { registerConsoleCommands() { this.embark.registerConsoleCommand({ - usage: 'resolve ', + usage: 'resolve [name]', description: __('Resolves an ENS name'), matches: (cmd) => { let [cmdName] = cmd.split(' '); @@ -104,7 +104,7 @@ class ENS { }); this.embark.registerConsoleCommand({ - usage: 'lookup
', + usage: 'lookup [address]', description: __('Lookup an ENS address'), matches: (cmd) => { let [cmdName] = cmd.split(' '); @@ -118,7 +118,7 @@ class ENS { this.embark.registerConsoleCommand({ - usage: 'registerSubDomain
', + usage: 'registerSubDomain [subDomain] [address]', description: __('Register an ENS sub-domain'), matches: (cmd) => { let [cmdName] = cmd.split(' '); diff --git a/packages/embark/src/lib/modules/plugin_cmd/index.js b/packages/embark/src/lib/modules/plugin_cmd/index.js index d788419eb..e6668aa2e 100644 --- a/packages/embark/src/lib/modules/plugin_cmd/index.js +++ b/packages/embark/src/lib/modules/plugin_cmd/index.js @@ -13,7 +13,7 @@ class PluginCommand { registerCommand() { this.embark.registerConsoleCommand({ description: "Installs a plugin in the Dapp. eg: plugin install embark-solc", - usage: "plugin install ", + usage: "plugin install [package]", matches: (cmd) => { const [cmdName] = cmd.split(' '); return cmdName === 'plugin'; diff --git a/packages/embark/src/lib/modules/profiler/index.js b/packages/embark/src/lib/modules/profiler/index.js index 8601fa313..a0387455b 100644 --- a/packages/embark/src/lib/modules/profiler/index.js +++ b/packages/embark/src/lib/modules/profiler/index.js @@ -71,7 +71,7 @@ class Profiler { registerConsoleCommand() { this.embark.registerConsoleCommand({ description: "Outputs the function profile of a contract", - usage: "profile ", + usage: "profile [contractName]", matches: (cmd) => { const [cmdName] = cmd.split(' '); return cmdName === 'profile';