Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CLI entry point #2157

Merged
merged 14 commits into from
Apr 21, 2019
Prev Previous commit
Next Next commit
review changes
  • Loading branch information
bartlomieju committed Apr 21, 2019
commit c9ce8b451ac7a61de84b6be989d6a9731ad0cf8e
18 changes: 9 additions & 9 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn print_file_info(worker: &Worker, url: &str) {
}
}

fn get_worker_and_state(
fn create_worker_and_state(
flags: DenoFlags,
argv: Vec<String>,
) -> (Worker, ThreadSafeState) {
Expand Down Expand Up @@ -158,7 +158,7 @@ fn prefetch_or_info_command(
argv: Vec<String>,
print_info: bool,
) {
let (mut worker, state) = get_worker_and_state(flags, argv);
let (mut worker, state) = create_worker_and_state(flags, argv);

let main_module = state.main_module().unwrap();
let main_future = lazy(move || {
Expand All @@ -184,7 +184,7 @@ fn prefetch_or_info_command(
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ry PTAL at it. It seem that execute_mod_async does not evaluate and run file if prefetch is set to true, so simple letting worker finish the job seems to work fine. I'm not sure though


fn eval_command(flags: DenoFlags, argv: Vec<String>) {
let (mut worker, state) = get_worker_and_state(flags, argv);
let (mut worker, state) = create_worker_and_state(flags, argv);
// Wrap provided script in async function so asynchronous methods
// work. This is required until top-level await is not supported.
let js_source = format!(
Expand All @@ -210,7 +210,7 @@ fn eval_command(flags: DenoFlags, argv: Vec<String>) {
}

fn run_repl(flags: DenoFlags, argv: Vec<String>) {
let (mut worker, _state) = get_worker_and_state(flags, argv);
let (mut worker, _state) = create_worker_and_state(flags, argv);

// REPL situation.
let main_future = lazy(move || {
Expand All @@ -228,7 +228,7 @@ fn run_repl(flags: DenoFlags, argv: Vec<String>) {
}

fn run_script(flags: DenoFlags, argv: Vec<String>) {
let (mut worker, state) = get_worker_and_state(flags, argv);
let (mut worker, state) = create_worker_and_state(flags, argv);

let main_module = state.main_module().unwrap();
// Normal situation of executing a module.
Expand Down Expand Up @@ -291,8 +291,8 @@ fn main() {
("types", Some(_)) => {
types_command();
}
("eval", Some(info_match)) => {
let code: &str = info_match.value_of("code").unwrap();
("eval", Some(eval_match)) => {
let code: &str = eval_match.value_of("code").unwrap();
argv.extend(vec![code.to_string()]);
eval_command(flags, argv);
}
Expand All @@ -301,8 +301,8 @@ fn main() {
argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, argv, true);
}
("prefetch", Some(info_match)) => {
let file: &str = info_match.value_of("file").unwrap();
("prefetch", Some(prefetch_match)) => {
let file: &str = prefetch_match.value_of("file").unwrap();
argv.extend(vec![file.to_string()]);
prefetch_or_info_command(flags, argv, false);
}
Expand Down