diff options
author | Kevin (Kun) "Kassimo" Qian <kevinkassimo@gmail.com> | 2019-09-27 16:09:42 -0700 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-27 19:09:42 -0400 |
commit | 6efca6d1a17638136eadf39644f392f9107a4a6c (patch) | |
tree | 6aedab40214d21396122a97b4e6335a0f084a079 /cli | |
parent | d36391ad20afe56aaa6e42fd63597221636fdfcb (diff) |
Add Deno.hostname() (#3032)
Diffstat (limited to 'cli')
-rw-r--r-- | cli/Cargo.toml | 1 | ||||
-rw-r--r-- | cli/ops/mod.rs | 4 | ||||
-rw-r--r-- | cli/ops/os.rs | 11 |
3 files changed, 16 insertions, 0 deletions
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4cb59f171..8894980d7 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -45,6 +45,7 @@ serde = { version = "1.0.100", features = ["derive"] } serde_derive = "1.0.100" serde_json = { version = "1.0.40", features = [ "preserve_order" ] } source-map-mappings = "0.5.0" +sys-info = "0.5.8" tempfile = "3.1.0" termcolor = "1.0.5" tokio = "0.1.22" diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs index ea71fee9f..ab318438f 100644 --- a/cli/ops/mod.rs +++ b/cli/ops/mod.rs @@ -83,6 +83,7 @@ pub const OP_MAKE_TEMP_DIR: OpId = 55; pub const OP_CWD: OpId = 56; pub const OP_FETCH_ASSET: OpId = 57; pub const OP_DIAL_TLS: OpId = 58; +pub const OP_HOSTNAME: OpId = 59; pub fn dispatch( state: &ThreadSafeState, @@ -305,6 +306,9 @@ pub fn dispatch( OP_DIAL_TLS => { dispatch_json::dispatch(tls::op_dial_tls, state, control, zero_copy) } + OP_HOSTNAME => { + dispatch_json::dispatch(os::op_hostname, state, control, zero_copy) + } _ => panic!("bad op_id"), }; diff --git a/cli/ops/os.rs b/cli/ops/os.rs index d033dc9c3..770af404c 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -9,6 +9,7 @@ use deno::*; use log; use std::collections::HashMap; use std::env; +use sys_info; use url::Url; /// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts. @@ -126,3 +127,13 @@ pub fn op_is_tty( "stderr": atty::is(atty::Stream::Stderr), }))) } + +pub fn op_hostname( + state: &ThreadSafeState, + _args: Value, + _zero_copy: Option<PinnedBuf>, +) -> Result<JsonOp, ErrBox> { + state.check_env()?; + let hostname = sys_info::hostname().unwrap_or_else(|_| "".to_owned()); + Ok(JsonOp::Sync(json!(hostname))) +} |