From 184be99f5b6e85a6041e72dfdd0afda46e5f8619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 4 Feb 2020 20:24:33 +0100 Subject: refactor: CLI subcommands and argv (#3886) --- cli/state.rs | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'cli/state.rs') diff --git a/cli/state.rs b/cli/state.rs index 269264dbf..903c5871b 100644 --- a/cli/state.rs +++ b/cli/state.rs @@ -47,7 +47,7 @@ pub struct ThreadSafeState(Arc); pub struct State { pub global_state: ThreadSafeGlobalState, pub permissions: Arc>, - pub main_module: Option, + pub main_module: ModuleSpecifier, // TODO(ry) rename to worker_channels_internal pub worker_channels: WorkerChannels, /// When flags contains a `.import_map_path` option, the content of the @@ -240,7 +240,7 @@ impl ThreadSafeState { pub fn new( global_state: ThreadSafeGlobalState, shared_permissions: Option>>, - main_module: Option, + main_module: ModuleSpecifier, internal_channels: WorkerChannels, ) -> Result { let import_map: Option = @@ -285,7 +285,7 @@ impl ThreadSafeState { pub fn new_for_worker( global_state: ThreadSafeGlobalState, shared_permissions: Option>>, - main_module: Option, + main_module: ModuleSpecifier, internal_channels: WorkerChannels, ) -> Result { let seeded_rng = match global_state.flags.seed { @@ -389,19 +389,13 @@ impl ThreadSafeState { #[cfg(test)] pub fn mock( - argv: Vec, + main_module: &str, internal_channels: WorkerChannels, ) -> ThreadSafeState { - let module_specifier = if argv.is_empty() { - None - } else { - let module_specifier = ModuleSpecifier::resolve_url_or_path(&argv[0]) - .expect("Invalid entry module"); - Some(module_specifier) - }; - + let module_specifier = ModuleSpecifier::resolve_url_or_path(main_module) + .expect("Invalid entry module"); ThreadSafeState::new( - ThreadSafeGlobalState::mock(argv), + ThreadSafeGlobalState::mock(vec!["deno".to_string()]), None, module_specifier, internal_channels, @@ -438,8 +432,5 @@ impl ThreadSafeState { fn thread_safe() { fn f(_: S) {} let (int, _) = ThreadSafeState::create_channels(); - f(ThreadSafeState::mock( - vec![String::from("./deno"), String::from("hello.js")], - int, - )); + f(ThreadSafeState::mock("./hello.js", int)); } -- cgit v1.2.3