From 5ea6a13ead2a5cab0f578c8af5f0e0be88c3a08c Mon Sep 17 00:00:00 2001 From: gennyble Date: Wed, 18 Dec 2024 00:27:34 -0600 Subject: Ahhhhh --- converge/src/main.rs | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) mode change 100644 => 100755 converge/src/main.rs (limited to 'converge/src/main.rs') diff --git a/converge/src/main.rs b/converge/src/main.rs old mode 100644 new mode 100755 index 20f2683..74abe67 --- a/converge/src/main.rs +++ b/converge/src/main.rs @@ -1,32 +1,30 @@ use std::str::FromStr; use camino::Utf8PathBuf; +use scurvy::Argument; fn main() { - let mut args = std::env::args().skip(1); - let argc = args.len(); - if argc == 0 { - eprintln!("usage: converge [supporting files ...]"); - return; + let arguments = [ + Argument::arg("timdb", "path").help("time database generated with whenwasit"), + Argument::arg("part", "path").help("part converge is supposed to build"), + ]; + let cli = scurvy::parse(&arguments); + + let content: Utf8PathBuf = cli.parse_opt_or_die("part"); + let supporting: Vec = cli.free_opts().into_iter().map(Utf8PathBuf::from).collect(); + + let time = std::time::Instant::now(); + for idx in 0..100 { + let supporting = supporting.clone(); + let html = process(content.clone(), supporting); } + println!("{}ms for 100", time.elapsed().as_millis()); - let content = match args.next() { - None => { - eprintln!("usage: converge [supporting files ...]"); - return; - } - Some(path) => Utf8PathBuf::from(path), - }; - - let supporting = args.map(Utf8PathBuf::from).collect(); - - let html = process(content, supporting); - println!("{html}") + //println!("{html}") } fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie::Html { - println!("{content_file}"); - let raw = std::fs::read_to_string(&content_file).unwrap(); + let raw = std::fs::read_to_string(content_file).unwrap(); match Part::from_str(&raw) { Err(PartError::NoSetup) => cutie::Html::parse(raw), @@ -73,7 +71,7 @@ fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie html: &'a mut cutie::Html, ident: &str, ) -> &'a mut cutie::Tag { - match html.get_parent_that_contains_tag_name_mut(&ident) { + match html.get_parent_that_contains_tag_name_mut(ident) { None => { eprintln!("error processing file"); eprintln!("failed to find element with tag {ident}"); @@ -93,7 +91,6 @@ fn process(content_file: Utf8PathBuf, mut supporting: Vec) -> cutie tag.children.extend(content_html.nodes); } Opcode::Before => { - println!("BEFORE"); let predicate = |node: &cutie::Node| -> bool { if let cutie::Node::Tag(tag) = node { if tag.name == ident { -- cgit 1.4.1-3-g733a5