diff options
author | gurv-s <vargwin@gmail.com> | 2019-06-08 15:33:04 +0530 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-06-08 10:59:20 -0400 |
commit | 95eac608a6e9793307d6f19a546a2a980542b839 (patch) | |
tree | ba573695c191d62ba209adfa2b3db0faa8bde416 | |
parent | 564222bc104e07e17186edaeb0818bd7f6d91889 (diff) |
Make print_file_info async
-rw-r--r-- | cli/main.rs | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/cli/main.rs b/cli/main.rs index 891f18f39..c1873ebf1 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -51,6 +51,7 @@ use flags::DenoFlags; use flags::DenoSubcommand; use futures::lazy; use futures::Future; +use futures::future; use log::{LevelFilter, Metadata, Record}; use std::env; @@ -92,53 +93,55 @@ where } } -pub fn print_file_info(worker: &Worker, url: &str) { - let maybe_out = - state::fetch_module_meta_data_and_maybe_compile(&worker.state, url, "."); - if let Err(err) = maybe_out { - println!("{}", err); - return; - } - let out = maybe_out.unwrap(); - - println!("{} {}", ansi::bold("local:".to_string()), &(out.filename)); +pub fn print_file_info( + worker: Worker, + url: &str, +) -> impl Future<Item = Worker, Error = ()> { + worker::fetch_module_meta_data_and_maybe_compile_async( + &worker.state, + url, + ".", + ).and_then(move |out| { + println!("{} {}", ansi::bold("local:".to_string()), &(out.filename)); - println!( - "{} {}", - ansi::bold("type:".to_string()), - msg::enum_name_media_type(out.media_type) - ); - - if out.maybe_output_code_filename.is_some() { println!( "{} {}", - ansi::bold("compiled:".to_string()), - out.maybe_output_code_filename.as_ref().unwrap(), + ansi::bold("type:".to_string()), + msg::enum_name_media_type(out.media_type) ); - } - if out.maybe_source_map_filename.is_some() { - println!( - "{} {}", - ansi::bold("map:".to_string()), - out.maybe_source_map_filename.as_ref().unwrap() - ); - } + if out.maybe_output_code_filename.is_some() { + println!( + "{} {}", + ansi::bold("compiled:".to_string()), + out.maybe_output_code_filename.as_ref().unwrap(), + ); + } + + if out.maybe_source_map_filename.is_some() { + println!( + "{} {}", + ansi::bold("map:".to_string()), + out.maybe_source_map_filename.as_ref().unwrap() + ); + } - let modules = worker.modules.lock().unwrap(); - if let Some(deps) = modules.deps(&out.module_name) { - println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name); - if let Some(ref depsdeps) = deps.deps { - for d in depsdeps { - println!("{}", d); + let modules = worker.modules.lock().unwrap(); + if let Some(deps) = worker.modules.deps(&out.module_name) { + println!("{}{}", ansi::bold("deps:\n".to_string()), deps.name); + if let Some(ref depsdeps) = deps.deps { + for d in depsdeps { + println!("{}", d); + } } + } else { + println!( + "{} cannot retrieve full dependency graph", + ansi::bold("deps:".to_string()), + ); } - } else { - println!( - "{} cannot retrieve full dependency graph", - ansi::bold("deps:".to_string()), - ); - } + Ok(worker) + }).map_err(|err| println!("{}", err)) } fn create_worker_and_state( @@ -195,8 +198,11 @@ fn fetch_or_info_command( .execute_mod_async(&main_url, true) .and_then(move |()| { if print_info { - print_file_info(&worker, &main_module); + future::Either::A(print_file_info(worker, &main_module)) + } else { + future::Either::B(future::ok(worker)) } + }).and_then(|worker| { worker.then(|result| { js_check(result); Ok(()) |