Use getopts from crates.io

This commit is contained in:
Simon Sapin 2015-08-05 16:32:54 +02:00
parent 361d94d23e
commit 4bcb1dc926
4 changed files with 42 additions and 34 deletions

View file

@ -446,6 +446,14 @@ dependencies = [
"winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.1.22 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "getopts"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "gfx" name = "gfx"
version = "0.0.1" version = "0.0.1"
@ -1504,6 +1512,7 @@ dependencies = [
"bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "cssparser 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "euclid 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"html5ever 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "html5ever 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)",
"js 0.1.0 (git+https://github.com/servo/rust-mozjs)", "js 0.1.0 (git+https://github.com/servo/rust-mozjs)",

View file

@ -53,3 +53,4 @@ serde = "0.4"
serde_macros = "0.4" serde_macros = "0.4"
string_cache = "0.1" string_cache = "0.1"
lazy_static = "0.1" lazy_static = "0.1"
getopts = "0.2.11"

View file

@ -14,7 +14,6 @@
#![feature(optin_builtin_traits)] #![feature(optin_builtin_traits)]
#![feature(path_ext)] #![feature(path_ext)]
#![feature(plugin)] #![feature(plugin)]
#![feature(rustc_private)]
#![feature(slice_splits)] #![feature(slice_splits)]
#![feature(step_by)] #![feature(step_by)]
#![feature(step_trait)] #![feature(step_trait)]

View file

@ -8,7 +8,7 @@
use geometry::ScreenPx; use geometry::ScreenPx;
use euclid::size::{Size2D, TypedSize2D}; use euclid::size::{Size2D, TypedSize2D};
use getopts; use getopts::Options;
use num_cpus; use num_cpus;
use std::collections::HashSet; use std::collections::HashSet;
use std::cmp; use std::cmp;
@ -172,9 +172,9 @@ pub struct Opts {
pub exit_after_load: bool, pub exit_after_load: bool,
} }
fn print_usage(app: &str, opts: &[getopts::OptGroup]) { fn print_usage(app: &str, opts: &Options) {
let message = format!("Usage: {} [ options ... ] [URL]\n\twhere options include", app); let message = format!("Usage: {} [ options ... ] [URL]\n\twhere options include", app);
println!("{}", getopts::usage(&message, opts)); println!("{}", opts.usage(&message));
} }
pub fn print_debug_usage(app: &str) -> ! { pub fn print_debug_usage(app: &str) -> ! {
@ -278,37 +278,36 @@ pub fn default_opts() -> Opts {
pub fn from_cmdline_args(args: &[String]) { pub fn from_cmdline_args(args: &[String]) {
let (app_name, args) = args.split_first().unwrap(); let (app_name, args) = args.split_first().unwrap();
let opts = vec!( let mut opts = Options::new();
getopts::optflag("c", "cpu", "CPU painting (default)"), opts.optflag("c", "cpu", "CPU painting (default)");
getopts::optflag("g", "gpu", "GPU painting"), opts.optflag("g", "gpu", "GPU painting");
getopts::optopt("o", "output", "Output file", "output.png"), opts.optopt("o", "output", "Output file", "output.png");
getopts::optopt("s", "size", "Size of tiles", "512"), opts.optopt("s", "size", "Size of tiles", "512");
getopts::optopt("", "device-pixel-ratio", "Device pixels per px", ""), opts.optopt("", "device-pixel-ratio", "Device pixels per px", "");
getopts::optflag("e", "experimental", "Enable experimental web features"), opts.optflag("e", "experimental", "Enable experimental web features");
getopts::optopt("t", "threads", "Number of paint threads", "1"), opts.optopt("t", "threads", "Number of paint threads", "1");
getopts::optflagopt("p", "profile", "Profiler flag and output interval", "10"), opts.optflagopt("p", "profile", "Profiler flag and output interval", "10");
getopts::optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10"), opts.optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10");
getopts::optflag("x", "exit", "Exit after load flag"), opts.optflag("x", "exit", "Exit after load flag");
getopts::optopt("y", "layout-threads", "Number of threads to use for layout", "1"), opts.optopt("y", "layout-threads", "Number of threads to use for layout", "1");
getopts::optflag("i", "nonincremental-layout", "Enable to turn off incremental layout."), opts.optflag("i", "nonincremental-layout", "Enable to turn off incremental layout.");
getopts::optflag("", "no-ssl", "Disables ssl certificate verification."), opts.optflag("", "no-ssl", "Disables ssl certificate verification.");
getopts::optflagopt("", "userscripts", opts.optflagopt("", "userscripts",
"Uses userscripts in resources/user-agent-js, or a specified full path",""), "Uses userscripts in resources/user-agent-js, or a specified full path","");
getopts::optflag("z", "headless", "Headless mode"), opts.optflag("z", "headless", "Headless mode");
getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"), opts.optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure");
getopts::optflagopt("", "devtools", "Start remote devtools server on port", "6000"), opts.optflagopt("", "devtools", "Start remote devtools server on port", "6000");
getopts::optflagopt("", "webdriver", "Start remote WebDriver server on port", "7000"), opts.optflagopt("", "webdriver", "Start remote WebDriver server on port", "7000");
getopts::optopt("", "resolution", "Set window resolution.", "800x600"), opts.optopt("", "resolution", "Set window resolution.", "800x600");
getopts::optopt("u", "user-agent", "Set custom user agent string", "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)"), opts.optopt("u", "user-agent", "Set custom user agent string", "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)");
getopts::optflag("M", "multiprocess", "Run in multiprocess mode"), opts.optflag("M", "multiprocess", "Run in multiprocess mode");
getopts::optopt("Z", "debug", opts.optopt("Z", "debug",
"A comma-separated string of debug options. Pass help to show available options.", ""), "A comma-separated string of debug options. Pass help to show available options.", "");
getopts::optflag("h", "help", "Print this message"), opts.optflag("h", "help", "Print this message");
getopts::optopt("", "resources-path", "Path to find static resources", "/home/servo/resources"), opts.optopt("", "resources-path", "Path to find static resources", "/home/servo/resources");
getopts::optflag("", "sniff-mime-types" , "Enable MIME sniffing"), opts.optflag("", "sniff-mime-types" , "Enable MIME sniffing");
);
let opt_match = match getopts::getopts(args, &opts) { let opt_match = match opts.parse(args) {
Ok(m) => m, Ok(m) => m,
Err(f) => args_fail(&f.to_string()), Err(f) => args_fail(&f.to_string()),
}; };