mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
auto merge of #1277 : Adenilson/servo/implementingHelp, r=pcwalton
Executing servo browser for the first time doesn't make evident that it already supports several different flags. This patch implements a help message displaying the available options and a brief explanation on them, based on comments in source code (opts.rs). I implemented both short hand/long hand options using getopts::groups.
This commit is contained in:
commit
1dd80b9a6c
1 changed files with 25 additions and 10 deletions
|
@ -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)]
|
||||
|
@ -41,26 +41,41 @@ pub struct Opts {
|
|||
headless: bool,
|
||||
}
|
||||
|
||||
fn print_usage(app: &str, opts: &[groups::OptGroup]) {
|
||||
let message = format!("Usage: {} [ options ... ] [URL]\n\twhere options include", app);
|
||||
println(groups::usage(message, opts));
|
||||
}
|
||||
|
||||
pub fn from_cmdline_args(args: &[~str]) -> Opts {
|
||||
let app_name = args[0].to_str();
|
||||
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(app_name, 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(app_name, opts);
|
||||
fail!(~"servo asks that you provide 1 or more URLs")
|
||||
} else {
|
||||
opt_match.free.clone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue