From cd19da62d9efe37566fdeff16e37ed066edd3e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sun, 21 Apr 2019 17:34:18 +0200 Subject: Refactor CLI entry point (#2157) Changes "deno --types" to "deno types" and "deno --prefetch" to "deno prefetch" --- core/examples/http_bench.rs | 1 + core/flags.rs | 43 +------------------------------------------ 2 files changed, 2 insertions(+), 42 deletions(-) (limited to 'core') diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs index 7cacf79b0..ea8058019 100644 --- a/core/examples/http_bench.rs +++ b/core/examples/http_bench.rs @@ -191,6 +191,7 @@ fn main() { }); let args: Vec = env::args().collect(); + // NOTE: `--help` arg will display V8 help and exit let args = deno::v8_set_flags(args); log::set_logger(&LOGGER).unwrap(); diff --git a/core/flags.rs b/core/flags.rs index 2da35734d..4deca6e2d 100644 --- a/core/flags.rs +++ b/core/flags.rs @@ -5,17 +5,13 @@ use libc::c_char; use libc::c_int; use std::ffi::CStr; use std::ffi::CString; -use std::mem; use std::vec::Vec; /// Pass the command line arguments to v8. /// Returns a vector of command line arguments that V8 did not understand. -/// Translates --v8-options into a --help flag for V8. pub fn v8_set_flags(args: Vec) -> Vec { // deno_set_v8_flags(int* argc, char** argv) mutates argc and argv to remove // flags that v8 understands. - // First parse core args, then convert to a vector of C strings. - let (args, rest) = v8_set_flags_preprocess(args); // Make a new array, that can be modified by V8::SetFlagsFromCommandLine(), // containing mutable raw pointers to the individual command line args. @@ -43,42 +39,5 @@ pub fn v8_set_flags(args: Vec) -> Vec { let cstr = CStr::from_ptr(*ptr as *const c_char); let slice = cstr.to_str().unwrap(); slice.to_string() - }).chain(rest.into_iter()) - .collect() -} - -// Returns args passed to V8, followed by args passed to JS -fn v8_set_flags_preprocess(args: Vec) -> (Vec, Vec) { - let (rest, mut v8_args) = - args.into_iter().partition(|ref a| a.as_str() == "--help"); - - // Replace args being sent to V8 - for a in &mut v8_args { - if a == "--v8-options" { - mem::swap(a, &mut String::from("--help")); - } - } - (v8_args, rest) -} - -#[test] -fn test_v8_set_flags_preprocess_1() { - let js_args = v8_set_flags_preprocess(vec![ - "deno".to_string(), - "--v8-options".to_string(), - ]); - assert_eq!( - js_args, - (vec!["deno".to_string(), "--help".to_string()], vec![]) - ); -} - -#[test] -fn test_v8_set_flags_preprocess_2() { - let js_args = - v8_set_flags_preprocess(vec!["deno".to_string(), "--help".to_string()]); - assert_eq!( - js_args, - (vec!["deno".to_string()], vec!["--help".to_string()]) - ); + }).collect() } -- cgit v1.2.3