mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implemeting help message for servo browser app using groups::opts module.
Signed-off-by: Adenilson Cavalcanti <a.cavalcanti@sisa.samsung.com>
This commit is contained in:
parent
426d18ffb1
commit
b2adac0cf3
1 changed files with 24 additions and 10 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use azure::azure_hl::{BackendType, CairoBackend, CoreGraphicsBackend};
|
use azure::azure_hl::{BackendType, CairoBackend, CoreGraphicsBackend};
|
||||||
use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBackend};
|
use azure::azure_hl::{CoreGraphicsAcceleratedBackend, Direct2DBackend, SkiaBackend};
|
||||||
use extra::getopts;
|
use extra::getopts::groups;
|
||||||
|
|
||||||
/// Global flags for Servo, currently set on the command line.
|
/// Global flags for Servo, currently set on the command line.
|
||||||
#[deriving(Clone)]
|
#[deriving(Clone)]
|
||||||
|
@ -41,26 +41,40 @@ pub struct Opts {
|
||||||
headless: bool,
|
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 {
|
pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
||||||
let args = args.tail();
|
let args = args.tail();
|
||||||
|
|
||||||
let opts = ~[
|
let opts = ~[
|
||||||
getopts::optflag("c"), // CPU rendering
|
groups::optflag("c", "cpu", "CPU rendering"),
|
||||||
getopts::optopt("o"), // output file
|
groups::optopt("o", "output", "Output file", "output.png"),
|
||||||
getopts::optopt("r"), // rendering backend
|
groups::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
|
||||||
getopts::optopt("s"), // size of tiles
|
groups::optopt("s", "size", "Size of tiles", "512"),
|
||||||
getopts::optopt("t"), // threads to render with
|
groups::optopt("t", "threads", "Number of render threads", "1"),
|
||||||
getopts::optflagopt("p"), // profiler flag and output interval
|
groups::optflagopt("p", "profile", "Profiler flag and output interval", "10"),
|
||||||
getopts::optflag("x"), // exit after load flag
|
groups::optflag("x", "exit", "Exit after load flag"),
|
||||||
getopts::optflag("z"), // headless mode
|
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,
|
Ok(m) => m,
|
||||||
Err(f) => fail!(f.to_err_msg()),
|
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() {
|
let urls = if opt_match.free.is_empty() {
|
||||||
|
print_usage(opts);
|
||||||
fail!(~"servo asks that you provide 1 or more URLs")
|
fail!(~"servo asks that you provide 1 or more URLs")
|
||||||
} else {
|
} else {
|
||||||
opt_match.free.clone()
|
opt_match.free.clone()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue