option to write to file [CI SKIP]

This commit is contained in:
Drone CI 2019-03-25 14:40:10 +01:00 committed by Shimun
parent 3beb5cd830
commit 045e7f3ea8
2 changed files with 10 additions and 1 deletions

View File

@ -50,6 +50,13 @@ fn main() -> Result<(), Box<Error>> {
let mut handle = stdin.lock();
read_html(&mut handle)?
};
let mut out: Box<Write> = if let Some(path) = opt.output {
let mut file = File::open(&path)?;
Box::new(file)
} else {
Box::new(stdout())
};
let css_selector = opt.selector;
@ -75,7 +82,7 @@ fn main() -> Result<(), Box<Error>> {
// Let's get the actual text in this text node. A text node wraps around
// a RefCell<String>, so we need to call borrow() to get a &str out.
//let text = text_node.as_text().unwrap().borrow();
write!(stdout(), "{}", serialize_node(as_node)?);
write!(out, "{}", serialize_node(as_node)?);
/*if let Some(child) = as_node.first_child() {
//TODO: Convert Nodes to String, as this only works for Nodes containing plain text

View File

@ -9,4 +9,6 @@ pub struct Opts {
#[structopt(parse(from_os_str))]
pub input: Option<PathBuf>,
#[structopt(short = "o", long = "out", parse(from_os_str))]
pub output: Option<PathBuf>,
}