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

remove no longer needed DenoFlags fields

  • Loading branch information...
bartlomieju committed Apr 20, 2019
commit 172d927f48f55ceaf818066a9badb82dab0e0eac
@@ -23,9 +23,6 @@ pub struct DenoFlags {
pub no_prompts: bool,
pub types: bool,
pub prefetch: bool,
pub info: bool,
pub fmt: bool,
pub eval: bool,
}

impl<'a> From<ArgMatches<'a>> for DenoFlags {
This conversation was marked as resolved by bartlomieju

This comment has been minimized.

Copy link
@ry

ry Apr 20, 2019

Collaborator

Can this DenoFlags::<ArgMatches>::from implementation be combined into set_flags? I feel like parsing is now being broken up into two parts.

@@ -77,15 +74,6 @@ impl<'a> From<ArgMatches<'a>> for DenoFlags {
if matches.is_present("prefetch") {
flags.prefetch = true;
}
if matches.is_present("info") {
flags.info = true;
}
if matches.is_present("fmt") {
flags.fmt = true;
}
if matches.is_present("eval") {
flags.eval = true;
}

flags
}
@@ -139,7 +139,8 @@ fn get_worker_and_state(
}

fn info_command(flags: DenoFlags, argv: Vec<String>) {
let should_display_info = flags.info;
// TODO(bartlomieju) legacy, to be removed
let should_display_info = true;
let (mut worker, state) = get_worker_and_state(flags, argv);

if let Some(main_module) = state.main_module() {
@@ -151,7 +152,7 @@ fn info_command(flags: DenoFlags, argv: Vec<String>) {
let main_url = root_specifier_to_url(&main_module).unwrap();

worker
.execute_mod_async(&main_url, true)
.execute_mod_async(&main_url, should_display_info)
.and_then(move |worker| {
if should_display_info {
// Display file info and exit. Do not run file
@@ -166,6 +167,8 @@ fn info_command(flags: DenoFlags, argv: Vec<String>) {
}).map_err(|(err, _worker)| print_err_and_exit(err))
});
tokio_util::run(main_future);
} else {
panic!("unreachable");
}
}

This comment has been minimized.

Copy link
@bartlomieju

bartlomieju Apr 20, 2019

Author Contributor

@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


@@ -214,8 +217,7 @@ fn run_repl(flags: DenoFlags, argv: Vec<String>) {
}

fn run_script(flags: DenoFlags, argv: Vec<String>) {
let should_prefetch = flags.prefetch || flags.info;
let should_display_info = flags.info;
let should_prefetch = flags.prefetch;

let (mut worker, state) = get_worker_and_state(flags, argv);

@@ -232,11 +234,6 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
worker
.execute_mod_async(&main_url, should_prefetch)
.and_then(move |worker| {
if should_display_info {
// Display file info and exit. Do not run file
print_file_info(&worker, &main_module);
std::process::exit(0);
}
worker.then(|result| {
js_check(result);
Ok(())
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.