Skip to content

Commit

Permalink
Implemeting help message for servo browser app using groups::opts mod…
Browse files Browse the repository at this point in the history
…ule.

Signed-off-by: Adenilson Cavalcanti <a.cavalcanti@sisa.samsung.com>
  • Loading branch information
Adenilson Cavalcanti committed Nov 18, 2013
1 parent 426d18f commit b2adac0
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions src/components/gfx/opts.rs
Expand Up @@ -7,7 +7,7 @@

use azure::azure_hl::{BackendType, CairoBackend, CoreGraphicsBackend};
use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBackend};
use extra::getopts;
use extra::getopts::groups;

/// Global flags for Servo, currently set on the command line.
#[deriving(Clone)]
Expand Down Expand Up @@ -41,26 +41,40 @@ pub struct Opts {
headless: bool,
}

fn print_usage(opts: &[groups::OptGroup]) {
let message = format!("Usage: ./servo [ options ... ] [URL]\n\twhere options include");
println(groups::usage(message, opts));
}

pub fn from_cmdline_args(args: &[~str]) -> Opts {
let args = args.tail();

let opts = ~[
getopts::optflag("c"), // CPU rendering
getopts::optopt("o"), // output file
getopts::optopt("r"), // rendering backend
getopts::optopt("s"), // size of tiles
getopts::optopt("t"), // threads to render with
getopts::optflagopt("p"), // profiler flag and output interval
getopts::optflag("x"), // exit after load flag
getopts::optflag("z"), // headless mode
groups::optflag("c", "cpu", "CPU rendering"),
groups::optopt("o", "output", "Output file", "output.png"),
groups::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
groups::optopt("s", "size", "Size of tiles", "512"),
groups::optopt("t", "threads", "Number of render threads", "1"),
groups::optflagopt("p", "profile", "Profiler flag and output interval", "10"),
groups::optflag("x", "exit", "Exit after load flag"),
groups::optflag("z", "headless", "Headless mode"),
groups::optflag("h", "help", "Print this message")
];

let opt_match = match getopts::getopts(args, opts) {
let opt_match = match groups::getopts(args, opts) {
Ok(m) => m,
Err(f) => fail!(f.to_err_msg()),
};

if opt_match.opt_present("h") || opt_match.opt_present("help") {
print_usage(opts);
// TODO: how to return a null struct and let the caller know that
// it should abort?
fail!("")
};

let urls = if opt_match.free.is_empty() {
print_usage(opts);
fail!(~"servo asks that you provide 1 or more URLs")
} else {
opt_match.free.clone()
Expand Down

0 comments on commit b2adac0

Please sign in to comment.