Skip to content

Commit

Permalink
Remove flags::process
Browse files Browse the repository at this point in the history
It was doing two independent things:
- print help and exit
- set log level

It's better to do those explicitly in main.rs
  • Loading branch information
hayd authored and ry committed Nov 6, 2018
1 parent e1d5f82 commit 7a17e2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
16 changes: 0 additions & 16 deletions src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 2,9 @@
use getopts::Options;
use libc::c_int;
use libdeno;
use log;
use std::ffi::CStr;
use std::ffi::CString;
use std::mem;
use std::process::exit;
use std::vec::Vec;

// Creates vector of strings, Vec<String>
Expand All @@ -28,20 26,6 @@ pub struct DenoFlags {
pub types_flag: bool,
}

pub fn process(flags: &DenoFlags, usage_string: &str) {
if flags.help {
println!("{}", &usage_string);
exit(0);
}

let log_level = if flags.log_debug {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
};
log::set_max_level(log_level);
}

pub fn get_usage(opts: &Options) -> String {
format!(
"Usage: deno script.ts {}
Expand Down
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 81,19 @@ fn main() {
eprintln!("{}", err);
std::process::exit(1)
});

if flags.help {
println!("{}", &usage_string);
std::process::exit(0);
}

log::set_max_level(if flags.log_debug {
log::LevelFilter::Debug
} else {
log::LevelFilter::Info
});

let mut isolate = isolate::Isolate::new(flags, rest_argv, ops::dispatch);
flags::process(&isolate.state.flags, &usage_string);
tokio_util::init(|| {
isolate
.execute("deno_main.js", "denoMain();")
Expand Down

0 comments on commit 7a17e2a

Please sign in to comment.