Skip to content
Snippets Groups Projects
Verified Commit d44118cd authored by Louis's avatar Louis :fire:
Browse files

Write output

parent 1243df49
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ use lol_html::{element, rewrite_str, text, RewriteStrSettings};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::fs::File;
use std::io::Read;
use std::io::{Read, Write};
use std::sync::{Arc, Mutex};
use thiserror::Error;
......@@ -47,6 +47,8 @@ pub enum AppError {
InvalidOpfile(toml::de::Error),
#[error("Failed to match selector {0}")]
SelectorFailed(String),
#[error("Failed to apply edits {0}")]
EditsFailed(#[from] lol_html::errors::RewritingError),
}
pub type AppResult<T> = Result<T, AppError>;
......@@ -132,7 +134,20 @@ fn main() -> AppResult<()> {
},
);
println!("{}", html.unwrap());
let write_path = if args.inline {
Some(args.input.clone())
} else {
args.output
};
if let Some(path) = write_path {
File::create(&path)
.map_err(|_| AppError::FailedToOpen(args.input.clone()))?
.write_all(html?.as_bytes())
.map_err(|_| AppError::FailedToRead(args.input.clone()))?;
} else {
println!("{}", html?);
}
Ok(())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment