0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-30 11:15:13 -05:00
denoland-deno/src/main.rs

103 lines
2.1 KiB
Rust
Raw Normal View History

2019-01-01 19:58:40 -05:00
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
2018-07-26 17:54:22 -04:00
#[macro_use]
extern crate lazy_static;
#[macro_use]
2018-07-26 17:54:22 -04:00
extern crate log;
2018-10-26 21:34:42 -04:00
#[macro_use]
extern crate futures;
#[macro_use]
extern crate serde_json;
2018-07-26 17:54:22 -04:00
pub mod compiler;
pub mod deno_dir;
pub mod errors;
pub mod flags;
2018-07-26 17:54:22 -04:00
mod fs;
mod http_body;
mod http_util;
pub mod isolate;
pub mod js_errors;
pub mod libdeno;
pub mod msg;
2018-11-02 20:09:10 -04:00
pub mod msg_util;
2018-10-03 20:48:02 -04:00
pub mod ops;
pub mod permissions;
mod repl;
pub mod resolve_addr;
pub mod resources;
pub mod snapshot;
mod tokio_util;
mod tokio_write;
pub mod version;
pub mod workers;
2018-07-04 14:50:28 -04:00
#[cfg(unix)]
mod eager_unix;
2018-07-25 18:27:27 -07:00
use std::env;
2018-11-30 11:03:00 +08:00
use std::sync::Arc;
static LOGGER: Logger = Logger;
struct Logger;
impl log::Log for Logger {
2019-01-13 22:30:38 -08:00
fn enabled(&self, metadata: &log::Metadata<'_>) -> bool {
2018-08-07 13:33:36 -04:00
metadata.level() <= log::max_level()
}
2019-01-13 22:30:38 -08:00
fn log(&self, record: &log::Record<'_>) {
if self.enabled(record.metadata()) {
println!("{} RS - {}", record.level(), record.args());
}
}
fn flush(&self) {}
}
fn print_err_and_exit(err: js_errors::JSError) {
2018-12-10 17:50:41 -05:00
eprintln!("{}", err.to_string());
std::process::exit(1);
}
2018-06-16 01:43:23 +02:00
fn main() {
log::set_logger(&LOGGER).unwrap();
2018-09-22 01:03:24 -04:00
let args = env::args().collect();
let (flags, rest_argv, usage_string) =
flags::set_flags(args).unwrap_or_else(|err| {
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::Warn
});
let state = Arc::new(isolate::IsolateState::new(flags, rest_argv, None));
let snapshot = snapshot::deno_snapshot();
let isolate = isolate::Isolate::new(snapshot, state, ops::dispatch);
tokio_util::init(|| {
// Setup runtime.
isolate
.execute("denoMain();")
.unwrap_or_else(print_err_and_exit);
// Execute input file.
if isolate.state.argv.len() > 1 {
let input_filename = &isolate.state.argv[1];
isolate
.execute_mod(input_filename)
.unwrap_or_else(print_err_and_exit);
}
isolate.event_loop().unwrap_or_else(print_err_and_exit);
});
2018-06-16 01:43:23 +02:00
}