2020-01-02 15:13:47 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-07-06 21:45:39 -04:00
|
|
|
|
2019-09-02 17:07:11 -04:00
|
|
|
import { sendSync } from "./dispatch_json.ts";
|
2018-07-06 11:20:35 -04:00
|
|
|
|
2020-02-22 18:46:52 -05:00
|
|
|
export function loadavg(): number[] {
|
2020-02-25 09:14:27 -05:00
|
|
|
return sendSync("op_loadavg");
|
2020-02-22 18:46:52 -05:00
|
|
|
}
|
2019-02-02 22:05:30 -05:00
|
|
|
|
2019-09-27 19:09:42 -04:00
|
|
|
export function hostname(): string {
|
2020-02-25 09:14:27 -05:00
|
|
|
return sendSync("op_hostname");
|
2019-09-27 19:09:42 -04:00
|
|
|
}
|
|
|
|
|
2020-02-24 08:35:45 -05:00
|
|
|
export function osRelease(): string {
|
2020-02-25 09:14:27 -05:00
|
|
|
return sendSync("op_os_release");
|
2020-02-24 08:35:45 -05:00
|
|
|
}
|
|
|
|
|
2019-08-23 01:30:14 -04:00
|
|
|
export function exit(code = 0): never {
|
2020-02-25 09:14:27 -05:00
|
|
|
sendSync("op_exit", { code });
|
2020-03-11 10:49:53 -04:00
|
|
|
throw new Error("Code not reachable");
|
2018-07-06 11:20:35 -04:00
|
|
|
}
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
function setEnv(key: string, value: string): void {
|
2020-02-25 09:14:27 -05:00
|
|
|
sendSync("op_set_env", { key, value });
|
2019-03-09 12:30:38 -05:00
|
|
|
}
|
|
|
|
|
2019-10-02 11:55:28 -04:00
|
|
|
function getEnv(key: string): string | undefined {
|
2020-02-25 09:14:27 -05:00
|
|
|
return sendSync("op_get_env", { key })[0];
|
2019-10-02 11:55:28 -04:00
|
|
|
}
|
|
|
|
|
2020-06-09 08:58:30 -04:00
|
|
|
function deleteEnv(key: string): void {
|
|
|
|
sendSync("op_delete_env", { key });
|
|
|
|
}
|
|
|
|
|
2020-04-29 14:48:19 -04:00
|
|
|
export const env = {
|
|
|
|
get: getEnv,
|
2020-07-06 21:45:39 -04:00
|
|
|
toObject(): Record<string, string> {
|
2020-04-29 14:48:19 -04:00
|
|
|
return sendSync("op_env");
|
|
|
|
},
|
|
|
|
set: setEnv,
|
2020-06-09 08:58:30 -04:00
|
|
|
delete: deleteEnv,
|
2020-04-29 14:48:19 -04:00
|
|
|
};
|
2019-01-28 20:41:28 -05:00
|
|
|
|
2019-08-06 17:05:47 -04:00
|
|
|
export function execPath(): string {
|
2020-02-25 09:14:27 -05:00
|
|
|
return sendSync("op_exec_path");
|
2019-08-06 17:05:47 -04:00
|
|
|
}
|