From 4bcb1dc926728ec2a40d32f719bce038bd84981b Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Wed, 5 Aug 2015 16:32:54 +0200 Subject: [PATCH] Use getopts from crates.io --- components/servo/Cargo.lock | 9 +++++ components/util/Cargo.toml | 1 + components/util/lib.rs | 1 - components/util/opts.rs | 65 ++++++++++++++++++------------------- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 2804a772b76..8fdb0e68282 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -446,6 +446,14 @@ dependencies = [ "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]] name = "gfx" version = "0.0.1" @@ -1504,6 +1512,7 @@ dependencies = [ "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)", "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)", "ipc-channel 0.1.0 (git+https://github.com/pcwalton/ipc-channel)", "js 0.1.0 (git+https://github.com/servo/rust-mozjs)", diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 5b8e9f726f8..e8b5e56f9f6 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -53,3 +53,4 @@ serde = "0.4" serde_macros = "0.4" string_cache = "0.1" lazy_static = "0.1" +getopts = "0.2.11" diff --git a/components/util/lib.rs b/components/util/lib.rs index df3f90f5dfb..c8cc8a9770c 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -14,7 +14,6 @@ #![feature(optin_builtin_traits)] #![feature(path_ext)] #![feature(plugin)] -#![feature(rustc_private)] #![feature(slice_splits)] #![feature(step_by)] #![feature(step_trait)] diff --git a/components/util/opts.rs b/components/util/opts.rs index 564f1108d3d..d216e463fac 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -8,7 +8,7 @@ use geometry::ScreenPx; use euclid::size::{Size2D, TypedSize2D}; -use getopts; +use getopts::Options; use num_cpus; use std::collections::HashSet; use std::cmp; @@ -172,9 +172,9 @@ pub struct Opts { 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); - println!("{}", getopts::usage(&message, opts)); + println!("{}", opts.usage(&message)); } pub fn print_debug_usage(app: &str) -> ! { @@ -278,37 +278,36 @@ pub fn default_opts() -> Opts { pub fn from_cmdline_args(args: &[String]) { let (app_name, args) = args.split_first().unwrap(); - let opts = vec!( - getopts::optflag("c", "cpu", "CPU painting (default)"), - getopts::optflag("g", "gpu", "GPU painting"), - getopts::optopt("o", "output", "Output file", "output.png"), - getopts::optopt("s", "size", "Size of tiles", "512"), - getopts::optopt("", "device-pixel-ratio", "Device pixels per px", ""), - getopts::optflag("e", "experimental", "Enable experimental web features"), - getopts::optopt("t", "threads", "Number of paint threads", "1"), - getopts::optflagopt("p", "profile", "Profiler flag and output interval", "10"), - getopts::optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10"), - getopts::optflag("x", "exit", "Exit after load flag"), - getopts::optopt("y", "layout-threads", "Number of threads to use for layout", "1"), - getopts::optflag("i", "nonincremental-layout", "Enable to turn off incremental layout."), - getopts::optflag("", "no-ssl", "Disables ssl certificate verification."), - getopts::optflagopt("", "userscripts", - "Uses userscripts in resources/user-agent-js, or a specified full path",""), - getopts::optflag("z", "headless", "Headless mode"), - getopts::optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"), - getopts::optflagopt("", "devtools", "Start remote devtools server on port", "6000"), - getopts::optflagopt("", "webdriver", "Start remote WebDriver server on port", "7000"), - getopts::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)"), - getopts::optflag("M", "multiprocess", "Run in multiprocess mode"), - getopts::optopt("Z", "debug", - "A comma-separated string of debug options. Pass help to show available options.", ""), - getopts::optflag("h", "help", "Print this message"), - getopts::optopt("", "resources-path", "Path to find static resources", "/home/servo/resources"), - getopts::optflag("", "sniff-mime-types" , "Enable MIME sniffing"), - ); + let mut opts = Options::new(); + opts.optflag("c", "cpu", "CPU painting (default)"); + opts.optflag("g", "gpu", "GPU painting"); + opts.optopt("o", "output", "Output file", "output.png"); + opts.optopt("s", "size", "Size of tiles", "512"); + opts.optopt("", "device-pixel-ratio", "Device pixels per px", ""); + opts.optflag("e", "experimental", "Enable experimental web features"); + opts.optopt("t", "threads", "Number of paint threads", "1"); + opts.optflagopt("p", "profile", "Profiler flag and output interval", "10"); + opts.optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10"); + opts.optflag("x", "exit", "Exit after load flag"); + opts.optopt("y", "layout-threads", "Number of threads to use for layout", "1"); + opts.optflag("i", "nonincremental-layout", "Enable to turn off incremental layout."); + opts.optflag("", "no-ssl", "Disables ssl certificate verification."); + opts.optflagopt("", "userscripts", + "Uses userscripts in resources/user-agent-js, or a specified full path",""); + opts.optflag("z", "headless", "Headless mode"); + opts.optflag("f", "hard-fail", "Exit on task failure instead of displaying about:failure"); + opts.optflagopt("", "devtools", "Start remote devtools server on port", "6000"); + opts.optflagopt("", "webdriver", "Start remote WebDriver server on port", "7000"); + opts.optopt("", "resolution", "Set window resolution.", "800x600"); + opts.optopt("u", "user-agent", "Set custom user agent string", "NCSA Mosaic/1.0 (X11;SunOS 4.1.4 sun4m)"); + opts.optflag("M", "multiprocess", "Run in multiprocess mode"); + opts.optopt("Z", "debug", + "A comma-separated string of debug options. Pass help to show available options.", ""); + opts.optflag("h", "help", "Print this message"); + opts.optopt("", "resources-path", "Path to find static resources", "/home/servo/resources"); + 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, Err(f) => args_fail(&f.to_string()), };