-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
88 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import std/[json, options] | ||
import scripting_api, misc/myjsonutils | ||
|
||
## This file is auto generated, don't modify. | ||
|
||
|
||
proc process_runProcess_void_PluginService_string_seq_string_Option_string_Option_string_bool_wasm( | ||
arg: cstring): cstring {.importc.} | ||
proc runProcess*(process: string; args: seq[string]; | ||
callback: Option[string] = string.none; | ||
workingDir: Option[string] = string.none; eval: bool = false) {. | ||
gcsafe, raises: [].} = | ||
var argsJson = newJArray() | ||
argsJson.add process.toJson() | ||
argsJson.add args.toJson() | ||
argsJson.add callback.toJson() | ||
argsJson.add workingDir.toJson() | ||
argsJson.add eval.toJson() | ||
let argsJsonString = $argsJson | ||
let res {.used.} = process_runProcess_void_PluginService_string_seq_string_Option_string_Option_string_bool_wasm( | ||
argsJsonString.cstring) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import std/[tables, options, json, os, strutils] | ||
import results | ||
import misc/[custom_async, custom_logger, myjsonutils, util, async_process] | ||
import scripting/[expose, scripting_base] | ||
import workspaces/workspace | ||
import service, dispatch_tables, vfs, vfs_local, vfs_service | ||
|
||
{.push gcsafe.} | ||
{.push raises: [].} | ||
|
||
logCategory "plugin-api-process" | ||
|
||
########################################################################### | ||
|
||
proc runProcessImpl(self: PluginService, process: string, args: seq[string], callback: Option[string] = string.none, workingDir: Option[string] = string.none, eval: bool = false) {.async: (raises: []).} = | ||
type ResultType = tuple[output: string, err: string] | ||
|
||
let workingDir = if workingDir.getSome(wd): | ||
let vfs = self.services.getService(VFSService).get.vfs | ||
vfs.localize(wd) | ||
else: | ||
let workspace = self.services.getService(Workspace).get | ||
workspace.path | ||
|
||
try: | ||
let (output, err) = await runProcessAsyncOutput(process, args, workingDir=workingDir, eval=eval) | ||
log lvlDebug, &"runProcess '{process} {args.join($' ')}' in '{workingDir}'" | ||
if callback.getSome(c): | ||
discard self.callScriptAction(c, (output: output, err: err).some.toJson) | ||
|
||
except CatchableError as e: | ||
log lvlError, &"Failed to run process '{process}': {e.msg}" | ||
if callback.getSome(c): | ||
discard self.callScriptAction(c, ResultType.none.toJson) | ||
|
||
proc runProcess*(self: PluginService, process: string, args: seq[string], callback: Option[string] = string.none, workingDir: Option[string] = string.none, eval: bool = false) {.expose("process").} = | ||
asyncSpawn self.runProcessImpl(process, args, callback, workingDir, eval) | ||
|
||
addGlobalDispatchTable "process", genDispatchTable("process") |