mirror of
https://github.com/servo/servo.git
synced 2025-06-24 17:14:33 +01:00
Auto merge of #6473 - Ms2ger:args, r=metajack
Stop using env::set_exit_code. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6473) <!-- Reviewable:end -->
This commit is contained in:
commit
b26818a7b0
4 changed files with 85 additions and 90 deletions
|
@ -47,7 +47,8 @@ fn main() {
|
|||
env_logger::init().unwrap();
|
||||
|
||||
// Parse the command line options and store them globally
|
||||
if opts::from_cmdline_args(&*get_args()) {
|
||||
opts::from_cmdline_args(&*get_args());
|
||||
|
||||
setup_logging();
|
||||
|
||||
// Possibly interpret the `HOST_FILE` environment variable
|
||||
|
@ -87,7 +88,6 @@ fn main() {
|
|||
browser
|
||||
} = browser;
|
||||
browser.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
fn maybe_register_glutin_resize_handler(window: &Option<Rc<app::window::Window>>,
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
#![feature(alloc)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(exit_status)]
|
||||
#![feature(fnbox)]
|
||||
#![feature(hashmap_hasher)]
|
||||
#![feature(heap_api)]
|
||||
|
|
|
@ -19,6 +19,7 @@ use std::io::{self, Write};
|
|||
use std::fs::PathExt;
|
||||
use std::mem;
|
||||
use std::path::Path;
|
||||
use std::process;
|
||||
use std::ptr;
|
||||
use url::{self, Url};
|
||||
|
||||
|
@ -159,7 +160,7 @@ fn print_usage(app: &str, opts: &[getopts::OptGroup]) {
|
|||
println!("{}", getopts::usage(&message, opts));
|
||||
}
|
||||
|
||||
pub fn print_debug_usage(app: &str) {
|
||||
pub fn print_debug_usage(app: &str) -> ! {
|
||||
fn print_option(name: &str, description: &str) {
|
||||
println!("\t{:<35} {}", name, description);
|
||||
}
|
||||
|
@ -185,13 +186,15 @@ pub fn print_debug_usage(app: &str) {
|
|||
"Disable the style sharing cache.");
|
||||
|
||||
println!("");
|
||||
|
||||
process::exit(0)
|
||||
}
|
||||
|
||||
fn args_fail(msg: &str) {
|
||||
fn args_fail(msg: &str) -> ! {
|
||||
let mut stderr = io::stderr();
|
||||
stderr.write_all(msg.as_bytes()).unwrap();
|
||||
stderr.write_all(b"\n").unwrap();
|
||||
env::set_exit_status(1);
|
||||
process::exit(1)
|
||||
}
|
||||
|
||||
// Always use CPU painting on android.
|
||||
|
@ -244,7 +247,7 @@ pub fn default_opts() -> Opts {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_cmdline_args(args: &[String]) -> bool {
|
||||
pub fn from_cmdline_args(args: &[String]) {
|
||||
let app_name = args[0].to_string();
|
||||
let args = args.tail();
|
||||
|
||||
|
@ -279,15 +282,12 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
|
|||
|
||||
let opt_match = match getopts::getopts(args, &opts) {
|
||||
Ok(m) => m,
|
||||
Err(f) => {
|
||||
args_fail(&f.to_string());
|
||||
return false;
|
||||
}
|
||||
Err(f) => args_fail(&f.to_string()),
|
||||
};
|
||||
|
||||
if opt_match.opt_present("h") || opt_match.opt_present("help") {
|
||||
print_usage(&app_name, &opts);
|
||||
return false;
|
||||
process::exit(0);
|
||||
};
|
||||
|
||||
let debug_string = match opt_match.opt_str("Z") {
|
||||
|
@ -299,14 +299,12 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
|
|||
debug_options.insert(split.clone());
|
||||
}
|
||||
if debug_options.contains(&"help") {
|
||||
print_debug_usage(&app_name);
|
||||
return false;
|
||||
print_debug_usage(&app_name)
|
||||
}
|
||||
|
||||
let url = if opt_match.free.is_empty() {
|
||||
print_usage(&app_name, &opts);
|
||||
args_fail("servo asks that you provide a URL");
|
||||
return false;
|
||||
args_fail("servo asks that you provide a URL")
|
||||
} else {
|
||||
let ref url = opt_match.free[0];
|
||||
let cwd = env::current_dir().unwrap();
|
||||
|
@ -316,8 +314,7 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
|
|||
if Path::new(url).exists() {
|
||||
Url::from_file_path(&*cwd.join(url)).unwrap()
|
||||
} else {
|
||||
args_fail(&format!("File not found: {}", url));
|
||||
return false;
|
||||
args_fail(&format!("File not found: {}", url))
|
||||
}
|
||||
}
|
||||
Err(_) => panic!("URL parsing failed"),
|
||||
|
@ -423,7 +420,6 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
|
|||
};
|
||||
|
||||
set(opts);
|
||||
true
|
||||
}
|
||||
|
||||
static mut EXPERIMENTAL_ENABLED: bool = false;
|
||||
|
|
|
@ -62,7 +62,8 @@ fn main() {
|
|||
env_logger::init().unwrap();
|
||||
|
||||
// Parse the command line options and store them globally
|
||||
if opts::from_cmdline_args(env::args().collect::<Vec<_>>().as_slice()) {
|
||||
opts::from_cmdline_args(env::args().collect::<Vec<_>>().as_slice());
|
||||
|
||||
resource_task::global_init();
|
||||
|
||||
let window = if opts::get().headless {
|
||||
|
@ -103,6 +104,5 @@ fn main() {
|
|||
browser
|
||||
} = browser;
|
||||
browser.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue