diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-02-16 00:37:04 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-02-15 10:37:04 -0500 |
commit | 2241049c349443a971ba2558f373d62bbb7d9780 (patch) | |
tree | bd25d822e7d869acdda59541783ffcae716ca672 /js/process.ts | |
parent | 748e456cdb18912e780b69cc90023ef37f4d0c24 (diff) |
feat: env option in run api (#1773)
Diffstat (limited to 'js/process.ts')
-rw-r--r-- | js/process.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/js/process.ts b/js/process.ts index 495f6a9ce..c47a5b5dd 100644 --- a/js/process.ts +++ b/js/process.ts @@ -27,6 +27,7 @@ export type ProcessStdio = "inherit" | "piped" | "null"; export interface RunOptions { args: string[]; cwd?: string; + env?: { [key: string]: string }; stdout?: ProcessStdio; stderr?: ProcessStdio; stdin?: ProcessStdio; @@ -107,11 +108,24 @@ export function run(opt: RunOptions): Process { opt.args.map(a => builder.createString(a)) ); const cwdOffset = opt.cwd == null ? -1 : builder.createString(opt.cwd); + const kvOffset: flatbuffers.Offset[] = []; + if (opt.env) { + for (const [key, val] of Object.entries(opt.env)) { + const keyOffset = builder.createString(key); + const valOffset = builder.createString(String(val)); + msg.KeyValue.startKeyValue(builder); + msg.KeyValue.addKey(builder, keyOffset); + msg.KeyValue.addValue(builder, valOffset); + kvOffset.push(msg.KeyValue.endKeyValue(builder)); + } + } + const envOffset = msg.Run.createEnvVector(builder, kvOffset); msg.Run.startRun(builder); msg.Run.addArgs(builder, argsOffset); if (opt.cwd != null) { msg.Run.addCwd(builder, cwdOffset); } + msg.Run.addEnv(builder, envOffset); if (opt.stdin) { msg.Run.addStdin(builder, stdioMap(opt.stdin!)); } |