diff options
-rwxr-xr-x | src/components/main/servo.rs | 4 | ||||
-rw-r--r-- | src/components/util/opts.rs | 25 |
2 files changed, 19 insertions, 10 deletions
diff --git a/src/components/main/servo.rs b/src/components/main/servo.rs index 53071519273..a176fbb71f6 100755 --- a/src/components/main/servo.rs +++ b/src/components/main/servo.rs @@ -117,7 +117,7 @@ pub mod util; #[start] fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, proc() { - run(opts::from_cmdline_args(os::args())) + opts::from_cmdline_args(os::args()).map(run); }) } @@ -131,7 +131,7 @@ pub extern "C" fn android_start(argc: int, argv: **u8) -> int { args.push(str::raw::from_c_str(*argv.offset(i as int) as *i8)); } } - run(opts::from_cmdline_args(args)) + opts::from_cmdline_args(os::args()).map(run); }) } diff --git a/src/components/util/opts.rs b/src/components/util/opts.rs index 2f1d9777b8a..e33d5b87379 100644 --- a/src/components/util/opts.rs +++ b/src/components/util/opts.rs @@ -10,6 +10,8 @@ use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBacke use extra::getopts::groups; use std::num; use std::rt; +use std::io; +use std::os; /// Global flags for Servo, currently set on the command line. #[deriving(Clone)] @@ -59,7 +61,12 @@ fn print_usage(app: &str, opts: &[groups::OptGroup]) { println(groups::usage(message, opts)); } -pub fn from_cmdline_args(args: &[~str]) -> Opts { +fn args_fail(msg: &str) { + io::stderr().write_line(msg); + os::set_exit_status(1); +} + +pub fn from_cmdline_args(args: &[~str]) -> Option<Opts> { let app_name = args[0].to_str(); let args = args.tail(); @@ -80,19 +87,21 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts { let opt_match = match groups::getopts(args, opts) { Ok(m) => m, - Err(f) => fail!(f.to_err_msg()), + Err(f) => { + args_fail(f.to_err_msg()); + return None; + } }; if opt_match.opt_present("h") || opt_match.opt_present("help") { print_usage(app_name, opts); - // TODO: how to return a null struct and let the caller know that - // it should abort? - fail!("") + return None; }; let urls = if opt_match.free.is_empty() { print_usage(app_name, opts); - fail!(~"servo asks that you provide 1 or more URLs") + args_fail("servo asks that you provide 1 or more URLs"); + return None; } else { opt_match.free.clone() }; @@ -138,7 +147,7 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts { None => num::max(rt::default_sched_threads() * 3 / 4, 1), }; - Opts { + Some(Opts { urls: urls, render_backend: render_backend, n_render_threads: n_render_threads, @@ -151,5 +160,5 @@ pub fn from_cmdline_args(args: &[~str]) -> Opts { headless: opt_match.opt_present("z"), hard_fail: opt_match.opt_present("f"), bubble_widths_separately: opt_match.opt_present("b"), - } + }) } |