Commit 96a751b1 authored by yann300's avatar yann300

cmdInterpreter: debug, loadgist, loadswarm, setproviderurl

parent ae90c173
...@@ -6,6 +6,7 @@ var yo = require('yo-yo') ...@@ -6,6 +6,7 @@ var yo = require('yo-yo')
var async = require('async') var async = require('async')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var swarmgw = require('swarmgw')
var UniversalDApp = require('./universal-dapp.js') var UniversalDApp = require('./universal-dapp.js')
var UniversalDAppUI = require('./universal-dapp-ui.js') var UniversalDAppUI = require('./universal-dapp-ui.js')
...@@ -351,6 +352,42 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -351,6 +352,42 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
}) })
txlistener.startListening() txlistener.startListening()
// ----------------- Command Interpreter -----------------
/*
this module basically listen on user input (from terminal && editor)
and interpret them as commands
*/
var cmdInterpreter = new CommandInterpreter()
cmdInterpreter.event.register('debug', (hash) => {
startdebugging(hash)
})
cmdInterpreter.event.register('loadgist', (id) => {
loadFromGist({gist: id})
})
cmdInterpreter.event.register('loadswarm', (url) => {
swarmgw.get(url, function (err, ret) {
if (err) {
modalDialogCustom.log(`Unable to load ${url} from swarm: ${err}`)
} else {
ret = JSON.parse(ret)
for (var k in ret.sources) {
var url = ret.sources[k].urls[0] // @TODO retrieve all other content
swarmgw.get(url, (error, content) => {
if (!error) {
filesProviders['browser'].addReadOnly(k, content)
} else {
filesProviders['browser'].addReadOnly(k, `Cannot retrieve the content of ${url}: ${error}`)
}
})
}
}
})
})
cmdInterpreter.event.register('setproviderurl', (url) => {
executionContext.setContext('web3', url, true)
})
// ----------------- editor ---------------------------- // ----------------- editor ----------------------------
this._components.editor = new Editor({}) // @TODO: put into editorpanel this._components.editor = new Editor({}) // @TODO: put into editorpanel
var editor = self._components.editor // shortcut for the editor var editor = self._components.editor // shortcut for the editor
...@@ -436,6 +473,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -436,6 +473,7 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
// ----------------- editor panel ---------------------- // ----------------- editor panel ----------------------
this._components.editorpanel = new EditorPanel({ this._components.editorpanel = new EditorPanel({
api: { api: {
cmdInterpreter: cmdInterpreter,
editor: self._components.editor, editor: self._components.editor,
config: self._api.config, config: self._api.config,
txListener: txlistener, txListener: txlistener,
...@@ -503,23 +541,26 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -503,23 +541,26 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
} }
// ------------------ gist load ---------------- // ------------------ gist load ----------------
function loadFromGist (gistId) {
var loadingFromGist = gistHandler.handleLoad(queryParams.get(), function (gistId) { return gistHandler.handleLoad(gistId, function (gistId) {
$.ajax({ $.ajax({
url: 'https://api.github.com/gists/' + gistId, url: 'https://api.github.com/gists/' + gistId,
jsonp: 'callback', jsonp: 'callback',
dataType: 'jsonp', dataType: 'jsonp',
success: function (response) { success: function (response) {
if (response.data) { if (response.data) {
if (!response.data.files) { if (!response.data.files) {
modalDialogCustom.alert('Gist load error: ' + response.data.message) modalDialogCustom.alert('Gist load error: ' + response.data.message)
return return
}
loadFiles(response.data.files, 'gist')
} }
loadFiles(response.data.files, 'gist')
} }
} })
}) })
}) }
var loadingFromGist = loadFromGist(queryParams.get())
// insert ballot contract if there are no files available // insert ballot contract if there are no files available
if (!loadingFromGist) { if (!loadingFromGist) {
...@@ -608,21 +649,10 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -608,21 +649,10 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
} }
var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event) var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event)
// ----------------- Command Interpreter -----------------
/*
this module basically listen on user input (from terminal && editor)
and interpret them as command
*/
var cmdInterpreter = new CommandInterpreter()
cmdInterpreter.event.register('debug', (hash) => {
startdebugging(hash)
})
// ---------------- Righthand-panel -------------------- // ---------------- Righthand-panel --------------------
var rhpAPI = { var rhpAPI = {
config: config, config: config,
cmdInterpreter: cmdInterpreter,
setEditorSize (delta) { setEditorSize (delta) {
$('#righthand-panel').css('width', delta) $('#righthand-panel').css('width', delta)
self._view.centerpanel.style.right = delta + 'px' self._view.centerpanel.style.right = delta + 'px'
......
...@@ -71,8 +71,8 @@ class Terminal { ...@@ -71,8 +71,8 @@ class Terminal {
self.registerCommand('error', self._blocksRenderer('error'), { activate: true }) self.registerCommand('error', self._blocksRenderer('error'), { activate: true })
self.registerCommand('script', function execute (args, scopedCommands, append) { self.registerCommand('script', function execute (args, scopedCommands, append) {
var script = String(args[0]) var script = String(args[0])
if (self._api.cmdInterpreter && self._api.cmdInterpreter.interpret(script)) return
scopedCommands.log(`> ${script}`) scopedCommands.log(`> ${script}`)
if (self._api.cmdInterpreter && self._api.cmdInterpreter.interpret(script)) return
self._shell(script, scopedCommands, function (error, output) { self._shell(script, scopedCommands, function (error, output) {
if (error) scopedCommands.error(error) if (error) scopedCommands.error(error)
else scopedCommands.log(output) else scopedCommands.log(output)
......
...@@ -8,23 +8,15 @@ class CmdInterpreter { ...@@ -8,23 +8,15 @@ class CmdInterpreter {
} }
interpret (cmd) { interpret (cmd) {
if (!cmd) return false if (!cmd) return false
for (var c in commands) { var accept = commandsRegEx.exec(cmd)
if (commands[c].exec(cmd)) { if (accept) {
commands[c].action(this, cmd) this.event.trigger(accept[1], [cmd.replace(commandsRegEx, '')])
return true return accept[1]
}
} }
return false return null
} }
} }
var commands = [ var commandsRegEx = /^remix:(debug|loadgist|setproviderurl|loadswarm)\s/
{
command: /^debug /,
action: (self, command) => {
self.event.trigger('debug', command.replace('debug ', ''))
}
}
]
module.exports = CmdInterpreter module.exports = CmdInterpreter
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment