implemented `execute` terminal command

pull/3094/head
Evgeniy Filatov 6 years ago
parent 7390d0ad7b
commit e4e2f0b646
  1. 40
      src/lib/cmdInterpreterAPI.js

@ -17,6 +17,7 @@ class CmdInterpreterAPI {
self._components.terminal = terminal self._components.terminal = terminal
self._deps = { self._deps = {
app: self._components.registry.get('app').api, app: self._components.registry.get('app').api,
fileManager: self._components.registry.get('filemanager').api,
editor: self._components.registry.get('editor').api editor: self._components.registry.get('editor').api
} }
self.commandHelp = { self.commandHelp = {
@ -24,6 +25,7 @@ class CmdInterpreterAPI {
'remix.loadgist(id)': 'Load a gist in the file explorer.', 'remix.loadgist(id)': 'Load a gist in the file explorer.',
'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm or ipfs.', 'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm or ipfs.',
'remix.setproviderurl(url)': 'Change the current provider to Web3 provider and set the url endpoint.', 'remix.setproviderurl(url)': 'Change the current provider to Web3 provider and set the url endpoint.',
'remix.execute(filepath)': 'Run the script specified by file path. If filepath is empty, script currently displayed in the editor is executed.',
'remix.exeCurrent()': 'Run the script currently displayed in the editor', 'remix.exeCurrent()': 'Run the script currently displayed in the editor',
'remix.help()': 'Display this help message' 'remix.help()': 'Display this help message'
} }
@ -70,14 +72,44 @@ class CmdInterpreterAPI {
}) })
} }
exeCurrent (cb) { exeCurrent (cb) {
return this.execute(undefined, cb)
}
execute (file, cb) {
const self = this const self = this
var content = self._deps.editor.currentContent()
if (!content) { function _execute (content, cb) {
toolTip('no content to execute') if (!content) {
toolTip('no content to execute')
if (cb) cb()
return
}
self._components.terminal.commands.script(content)
}
if (typeof file === 'undefined') {
var content = self._deps.editor.currentContent()
_execute(content, cb)
return
}
var provider = self._deps.fileManager.fileProviderOf(file)
if (!provider) {
toolTip(`provider for path ${file} not found`)
if (cb) cb() if (cb) cb()
return return
} }
self._components.terminal.commands.script(content)
provider.get(file, (error, content) => {
if (error) {
toolTip(error)
if (cb) cb()
return
}
_execute(content, cb)
})
} }
help (cb) { help (cb) {
const self = this const self = this

Loading…
Cancel
Save