mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Add command line parsing
This commit is contained in:
parent
d550defdf3
commit
e0149a6043
3 changed files with 54 additions and 1 deletions
47
src/servo/opts.rs
Normal file
47
src/servo/opts.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#[doc = "
|
||||||
|
|
||||||
|
Configuration options for a single run of the servo application. Created
|
||||||
|
from command line arguments.
|
||||||
|
|
||||||
|
"];
|
||||||
|
|
||||||
|
type opts = {
|
||||||
|
urls: [str],
|
||||||
|
render_mode: render_mode
|
||||||
|
};
|
||||||
|
|
||||||
|
enum render_mode {
|
||||||
|
screen,
|
||||||
|
file(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_cmdline_args(args: [str]) -> opts {
|
||||||
|
import std::getopts;
|
||||||
|
|
||||||
|
let args = args.tail();
|
||||||
|
|
||||||
|
let opts = [
|
||||||
|
getopts::optopt("o")
|
||||||
|
];
|
||||||
|
|
||||||
|
let match = alt getopts::getopts(args, opts) {
|
||||||
|
result::ok(m) { m }
|
||||||
|
result::err(f) { fail getopts::fail_str(f) }
|
||||||
|
};
|
||||||
|
|
||||||
|
let urls = if match.free.is_empty() {
|
||||||
|
fail "servo asks that you provide 1 or more URLs"
|
||||||
|
} else {
|
||||||
|
match.free
|
||||||
|
};
|
||||||
|
|
||||||
|
let render_mode = alt getopts::opt_maybe_str(match, "o") {
|
||||||
|
some(output_file) { file(output_file) }
|
||||||
|
none { screen }
|
||||||
|
};
|
||||||
|
|
||||||
|
{
|
||||||
|
urls: urls,
|
||||||
|
render_mode: render_mode
|
||||||
|
}
|
||||||
|
}
|
|
@ -49,3 +49,4 @@ mod util {
|
||||||
}
|
}
|
||||||
|
|
||||||
mod content;
|
mod content;
|
||||||
|
mod opts;
|
|
@ -6,6 +6,11 @@ import gfx::renderer;
|
||||||
import platform::osmain;
|
import platform::osmain;
|
||||||
|
|
||||||
fn main(args: [str]) {
|
fn main(args: [str]) {
|
||||||
|
run(opts::from_cmdline_args(args))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(opts: opts::opts) {
|
||||||
|
|
||||||
// The platform event handler thread
|
// The platform event handler thread
|
||||||
let osmain = osmain::osmain();
|
let osmain = osmain::osmain();
|
||||||
|
|
||||||
|
@ -23,7 +28,7 @@ fn main(args: [str]) {
|
||||||
let content = content::content(layout);
|
let content = content::content(layout);
|
||||||
|
|
||||||
// Send each file to render then wait for keypress
|
// Send each file to render then wait for keypress
|
||||||
for args.tail().each { |filename|
|
for opts.urls.each { |filename|
|
||||||
#debug["master: Sending filename `%s`", filename];
|
#debug["master: Sending filename `%s`", filename];
|
||||||
content.send(content::parse(filename));
|
content.send(content::parse(filename));
|
||||||
#debug["master: Waiting for keypress"];
|
#debug["master: Waiting for keypress"];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue