Skip to content

Commit

Permalink
Pass the Inputs struct for as long as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
gabebw committed Aug 31, 2019
1 parent 5473013 commit f76f44b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn main() {

match read_inputs() {
Ok(inputs) => {
match parse(&inputs.html, &inputs.selector) {
match parse(inputs) {
Ok(result) => {
for r in result {
println!("{}", &r.trim());
Expand Down Expand Up @@ -66,10 +66,10 @@ fn select(document: scraper::Html, captures: regex::Captures) -> Result<Vec<Stri
}
}

fn parse(html: &str, selector: &str) -> Result<Vec<String>, String> {
let document = Html::parse_document(html);
fn parse(inputs: Inputs) -> Result<Vec<String>, String> {
let document = Html::parse_document(&inputs.html);
let re = Regex::new(r"(?P<selector>.+) (?:(?P<text>\{text\})|(attr\{(?P<attr>[^}]+)\}))$").unwrap();
match re.captures(selector) {
match re.captures(&inputs.selector) {
Some(captures) => select(document, captures),
None => {
Err("Please specify {text} or attr{ATTRIBUTE}".to_string())
Expand Down

0 comments on commit f76f44b

Please sign in to comment.