Skip to content

Commit

Permalink
Clean up flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 22, 2018
1 parent 7a0670a commit 99faac8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
23 changes: 23 additions & 0 deletions src/flags.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
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;
use version;

// Creates vector of strings, Vec<String>
#[cfg(test)]
Expand All @@ -24,6 +27,24 @@ pub struct DenoFlags {
pub deps_flag: bool,
}

pub fn process(flags: &DenoFlags) {
if flags.help {
print_usage();
exit(0);
}

if flags.version {
version::print_version();
exit(0);
}

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

pub fn print_usage() {
println!(
"Usage: deno script.ts
Expand All @@ -41,6 +62,8 @@ pub fn print_usage() {

// Parses flags for deno. This does not do v8_set_flags() - call that separately.
pub fn set_flags(args: Vec<String>) -> (DenoFlags, Vec<String>) {
let args = v8_set_flags(args);

let mut flags = DenoFlags::default();
let mut rest = Vec::new();
let mut arg_iter = args.iter();
Expand Down
22 changes: 3 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,25 +48,9 @@ impl log::Log for Logger {
fn main() {
log::set_logger(&LOGGER).unwrap();

let js_args = flags::v8_set_flags(env::args().collect());

let mut isolate = Isolate::new(js_args);

if isolate.flags.help {
flags::print_usage();
std::process::exit(0);
}

if isolate.flags.version {
version::print_version();
std::process::exit(0);
}

let mut log_level = log::LevelFilter::Info;
if isolate.flags.log_debug {
log_level = log::LevelFilter::Debug;
}
log::set_max_level(log_level);
let args = env::args().collect();
let mut isolate = Isolate::new(args);
flags::process(&isolate.flags);

isolate
.execute("deno_main.js", "denoMain();")
Expand Down

0 comments on commit 99faac8

Please sign in to comment.