diff --git a/src/chiritori.rs b/src/chiritori.rs index a379af1..315c5be 100644 --- a/src/chiritori.rs +++ b/src/chiritori.rs @@ -1,6 +1,7 @@ use crate::{ code::{ formatter::{self, BlockFormatter, Formatter}, + list::build_list, remover::{ self, marker::{ @@ -15,6 +16,7 @@ use crate::{ factory::RemoveStrategies, }, removal_evaluator::RemovalEvaluator, + Remover, }, }, parser, tokenizer, @@ -25,8 +27,6 @@ use std::{ }; pub struct ChiritoriConfiguration { - pub delimiter_start: String, - pub delimiter_end: String, pub time_limited_configuration: TimeLimitedConfiguration, pub marker_tag_configuration: MarkerTagConfiguration, } @@ -42,14 +42,46 @@ pub struct MarkerTagConfiguration { pub marker_removal_tags: HashSet, } -pub fn clean(content: Rc, config: ChiritoriConfiguration) -> String { - let tokens = tokenizer::tokenize(&content, &config.delimiter_start, &config.delimiter_end); +pub fn clean( + content: Rc, + delimiters: (String, String), + config: ChiritoriConfiguration, +) -> String { + let (delimiter_start, delimiter_end) = delimiters; + let tokens = tokenizer::tokenize(&content, &delimiter_start, &delimiter_end); let parsed = parser::parse(&tokens); - let mut builder_map: HashMap<&str, Box> = HashMap::new(); + let remover = build_remover(config, content.clone()); + let (removed, markers) = remover.remove(parsed, &content); + let removed_pos = remover::get_removed_pos(&markers); + let formatter = build_formatters(); + let structure_formatters: Vec> = vec![Box::new( + formatter::block_indent_remover::BlockIndentRemover {}, + )]; + + formatter::format(&removed, &removed_pos, &formatter, &structure_formatters) +} + +pub fn list( + content: Rc, + delimiters: (String, String), + config: ChiritoriConfiguration, +) -> String { + let (delimiter_start, delimiter_end) = delimiters; + let tokens = tokenizer::tokenize(&content, &delimiter_start, &delimiter_end); + + let parsed = parser::parse(&tokens); + let remover = build_remover(config, content.clone()); + let (_, markers) = remover.remove(parsed, &content); + + build_list(&content, &markers) +} + +fn build_remover(config: ChiritoriConfiguration, content: Rc) -> Remover { + let mut builder_map: HashMap> = HashMap::new(); builder_map.insert( - &config.time_limited_configuration.tag_name, + config.time_limited_configuration.tag_name, Box::new( remover::removal_evaluator::time_limited_evaluator::TimeLimitedEvaluator { current_time: config.time_limited_configuration.current, @@ -59,7 +91,7 @@ pub fn clean(content: Rc, config: ChiritoriConfiguration) -> String { ); builder_map.insert( - &config.marker_tag_configuration.tag_name, + config.marker_tag_configuration.tag_name, Box::new( remover::removal_evaluator::marker_evaluator::MarkerEvaluator { marker_removal_names: config.marker_tag_configuration.marker_removal_tags, @@ -70,9 +102,7 @@ pub fn clean(content: Rc, config: ChiritoriConfiguration) -> String { let remove_strategy_map: RemoveStrategies = vec![ ( Box::new(UnwrapBlockMarkerAvailability::new("unwrap-block")), - Box::new(UnwrapBlockMarkerBuilder { - content: Rc::clone(&content), - }), + Box::new(UnwrapBlockMarkerBuilder { content }), ), ( Box::new(RangeMarkerAvailability::default()), @@ -80,20 +110,16 @@ pub fn clean(content: Rc, config: ChiritoriConfiguration) -> String { ), ]; - let (removed, markers) = remover::remove(parsed, &content, &builder_map, &remove_strategy_map); + Remover::new(builder_map, remove_strategy_map) +} - let removed_pos = remover::get_removed_pos(&markers); - let formatter: Vec> = vec![ +fn build_formatters() -> Vec> { + vec![ Box::new(formatter::indent_remover::IndentRemover {}), Box::new(formatter::empty_line_remover::EmptyLineRemover {}), Box::new(formatter::prev_line_break_remover::PrevLineBreakRemover {}), Box::new(formatter::next_line_break_remover::NextLineBreakRemover {}), - ]; - let structure_formatters: Vec> = vec![Box::new( - formatter::block_indent_remover::BlockIndentRemover {}, - )]; - - formatter::format(&removed, &removed_pos, &formatter, &structure_formatters) + ] } #[cfg(test)] @@ -105,10 +131,8 @@ mod tests { use std::io::prelude::*; use std::{fs::File, path::PathBuf}; - fn create_test_config(delimiter_start: &str, delimiter_end: &str) -> ChiritoriConfiguration { + fn create_test_config() -> ChiritoriConfiguration { ChiritoriConfiguration { - delimiter_start: String::from(delimiter_start), - delimiter_end: String::from(delimiter_end), time_limited_configuration: TimeLimitedConfiguration { tag_name: String::from("time-limited"), current: Local::now(), @@ -163,9 +187,9 @@ mod tests { "#, ); - - let config = create_test_config(""); - let result = clean(content.into(), config); + let config = create_test_config(); + let delimiters = (String::from("")); + let result = clean(content.into(), delimiters, config); assert_eq!(result, expected); } @@ -215,8 +239,9 @@ console.log("Temporary code while feature2 is not released") "#, ); - let config = create_test_config("/* <", "> */"); - let result = clean(content.into(), config); + let config = create_test_config(); + let delimiters = (String::from("/* <"), String::from("> */")); + let result = clean(content.into(), delimiters, config); assert_eq!(result, expected); } @@ -242,8 +267,9 @@ console.log("Temporary code while feature2 is not released") .read_to_string(&mut expected_content) .expect("Failed to load an expected content file"); - let config = create_test_config("/* <", "> */"); - let result = clean(input_content.into(), config); + let config = create_test_config(); + let delimiters = (String::from("/* <"), String::from("> */")); + let result = clean(input_content.into(), delimiters, config); assert_eq!(result, expected_content); } diff --git a/src/code.rs b/src/code.rs index 65352f1..1bf2a1e 100644 --- a/src/code.rs +++ b/src/code.rs @@ -1,3 +1,4 @@ pub mod formatter; +pub mod list; pub mod remover; pub mod utils; diff --git a/src/code/list.rs b/src/code/list.rs new file mode 100644 index 0000000..0ec9dff --- /dev/null +++ b/src/code/list.rs @@ -0,0 +1,129 @@ +use super::{ + remover::RemoveMarker, + utils::line_break_pos_finder::{find_next_line_break_pos, find_prev_line_break_pos}, +}; + +const MARKER_START: &str = "\x1b[32m_start\x1b[0m"; +const MARKER_END: &str = "\x1b[32m‾end\x1b[0m"; +const START_COLOR: &str = "\x1b[31m"; +const END_COLOR: &str = "\x1b[0m"; +const MARKER_START_LEN: usize = MARKER_START.len(); +const MARKER_END_LEN: usize = MARKER_END.len(); +const START_COLOR_LEN: usize = START_COLOR.len(); +const END_COLOR_LEN: usize = END_COLOR.len(); + +const HEAD_START: &str = "\n--------[ "; +const HEAD_END: &str = " ]--------\n"; + +pub fn build_item(content: &str, start: usize, end: usize) -> String { + if end - start == 0 || content.is_empty() { + return String::new(); + } + + let bytes = content.as_bytes(); + let line_start = find_prev_line_break_pos(content, bytes, start, false) + .map(|v| v + 1) + .unwrap_or(0); + let line_end_start_pos = find_prev_line_break_pos(content, bytes, end - 1, false) + .map(|v| v + 1) + .unwrap_or(0); + let line_end = + find_next_line_break_pos(content, bytes, end - 1, false).unwrap_or(content.len()); + + let color_start = start; + // If the end position is a line break (= line_end < end), it is not included. + let color_end = end.min(line_end); + + let marker_start_ofs_len = start - line_start; + let marker_end_ofs_len = end - line_end_start_pos - 1; + let mut result = String::with_capacity( + marker_start_ofs_len + + MARKER_START_LEN + + 1 + + START_COLOR_LEN + + (line_end - line_start) + + END_COLOR_LEN + + 1 + + marker_end_ofs_len + + MARKER_END_LEN, + ); + + result.push_str(&" ".repeat(marker_start_ofs_len)); + result.push_str(MARKER_START); + result.push('\n'); + result.push_str(&content[line_start..color_start]); + result.push_str(START_COLOR); + result.push_str(&content[color_start..color_end]); + result.push_str(END_COLOR); + result.push_str(&content[color_end..line_end]); + result.push('\n'); + result.push_str(&" ".repeat(marker_end_ofs_len)); + result.push_str(MARKER_END); + + result +} + +pub fn build_list(content: &str, markers: &[RemoveMarker]) -> String { + markers + .iter() + .zip(1..=markers.len()) + .map(|((range, _), idx)| { + let mut res = String::from(HEAD_START); + res.push_str(&idx.to_string()); + res.push_str(HEAD_END); + res.push_str(&build_item(content, range.start, range.end)); + + res + }) + .collect() +} + +#[cfg(test)] +mod tests { + use super::*; + use rstest::rstest; + use std::ops::Range; + + #[rstest] + // 0 10 + // 012345678901234567 + #[case("aaa+bbbb+ccc+dddd", 4..11, format!("{}{}+{}{}{}{}{}+{}{}", "", MARKER_START, "", START_COLOR, "bbbb+cc", END_COLOR, "c", " ", MARKER_END))] + #[case("aaa+bbbb+ccc+dddd", 3..11, format!("{}{}+{}{}{}{}{}+{}{}", " ", MARKER_START, "aaa", START_COLOR, "+bbbb+cc", END_COLOR, "c", " ", MARKER_END))] + #[case("aaa+bbbb+ccc+dddd", 2..11, format!("{}{}+{}{}{}{}{}+{}{}", " ", MARKER_START, "aa", START_COLOR, "a+bbbb+cc", END_COLOR, "c", " ", MARKER_END))] + #[case("aaa+bbbb+ccc+dddd", 4..12, format!("{}{}+{}{}{}{}{}+{}{}", "", MARKER_START, "", START_COLOR, "bbbb+ccc", END_COLOR, "", " ", MARKER_END))] + #[case("aaa+bbbb+ccc+dddd", 4..13, format!("{}{}+{}{}{}{}{}+{}{}", "", MARKER_START, "", START_COLOR, "bbbb+ccc", END_COLOR, "", " ", MARKER_END))] + #[case("aaa+bbbb+ccc+dddd", 4..16, format!("{}{}+{}{}{}{}{}+{}{}", "", MARKER_START, "", START_COLOR, "bbbb+ccc+ddd", END_COLOR, "d", " ", MARKER_END))] + #[case("abcd", 1..2, format!("{}{}+{}{}{}{}{}+{}{}", " ", MARKER_START, "a", START_COLOR, "b", END_COLOR, "cd", " ", MARKER_END))] + #[case("", 0..0, "")] + fn test_build_item( + #[case] content: &str, + #[case] range: Range, + #[case] expected: String, + ) { + let content = content.replace('+', "\n"); + + assert_eq!( + build_item(&content, range.start, range.end), + expected.replace('+', "\n") + ); + } + + #[test] + fn test_build_list() { + // 0123456789012345678 + let content = "aaaa+bbbb+cccc+dddd".replace('+', "\n"); + let markers = [(1..2, None), (7..12, None)]; + + let expected_item1 = build_item(&content, 1, 2); + let expected_item2 = build_item(&content, 7, 12); + + assert_eq!( + build_list(&content, &markers), + format!( + "{}1{}{}{}2{}{}", + HEAD_START, HEAD_END, expected_item1, HEAD_START, HEAD_END, expected_item2 + ) + .replace('+', "\n") + ) + } +} diff --git a/src/code/remover.rs b/src/code/remover.rs index 9796ca8..62a8dfd 100644 --- a/src/code/remover.rs +++ b/src/code/remover.rs @@ -9,112 +9,120 @@ use removal_evaluator::RemovalEvaluator; use std::collections::HashMap; use std::ops::Range; -type RemoveMarker = (Range, Option); +pub type RemoveMarker = (Range, Option); pub type RemovedMarker = (usize, Option); -pub fn remove( - content: Vec, - raw: &str, - builder_map: &HashMap<&str, Box>, - remove_strategy_map: &RemoveStrategies, -) -> (String, Vec) { - let markers = build_remove_marker(&content, builder_map, remove_strategy_map); - let mut new_content = raw.to_string(); - - for (marker, _) in markers.iter().rev() { - new_content.replace_range(marker.clone(), ""); - } +type RemovalEvaluators = HashMap>; - (new_content, markers) +pub struct Remover { + removal_evaluators: RemovalEvaluators, + remove_strategies: RemoveStrategies, } -pub fn get_removed_pos(markers: &[RemoveMarker]) -> Vec { - markers - .iter() - .fold( - (vec![], 0), - |(mut positions, mut removed_len), (marker, pair_pos)| { - positions.push((marker.start - removed_len, *pair_pos)); - removed_len += marker.end - marker.start; - (positions, removed_len) - }, - ) - .0 -} +impl Remover { + pub fn new(removal_evaluators: RemovalEvaluators, remove_strategies: RemoveStrategies) -> Self { + Self { + removal_evaluators, + remove_strategies, + } + } -fn build_remove_marker( - contents: &[ContentPart], - evaluator_map: &HashMap<&str, Box>, - remove_strategy_map: &RemoveStrategies, -) -> Vec { - contents.iter().fold(vec![], |mut acc, c| { - if let parser::ContentPart::Element(el) = c { - let marker = if is_skip(&el.start_element) { - None - } else { - evaluator_map - .get(el.start_element.name) - .and_then(|evaluator| match evaluator.is_removal(&el.start_element) { - true => create(el, remove_strategy_map), - false => None, - }) - .and_then(|(range, closed_range)| { - if !range.is_empty() { - Some((range, closed_range)) - } else { - None - } - }) - }; - - let child_markers = - build_remove_marker(&el.children, evaluator_map, remove_strategy_map); - - if let Some((mut marker, pair)) = marker { - let mut start_cursor = 0; - for (child_marker, _) in &child_markers { - if marker.contains(&child_marker.start) || marker.contains(&child_marker.end) { - marker = - marker.start.min(child_marker.start)..marker.end.max(child_marker.end) - } else { - break; - } - start_cursor += 1; - } + pub fn remove(&self, content: Vec, raw: &str) -> (String, Vec) { + let markers = self.build_remove_marker(&content); + let mut new_content = raw.to_string(); + + for (marker, _) in markers.iter().rev() { + new_content.replace_range(marker.clone(), ""); + } + + (new_content, markers) + } - if let Some(mut end_marker) = pair { - let mut end_cursor = child_markers.len(); - for (child_marker, _) in child_markers.iter().rev() { - if end_marker.contains(&child_marker.start) - || end_marker.contains(&child_marker.end) + pub fn build_remove_marker(&self, contents: &[ContentPart]) -> Vec { + contents.iter().fold(vec![], |mut acc, c| { + if let parser::ContentPart::Element(el) = c { + let marker = if is_skip(&el.start_element) { + None + } else { + self.removal_evaluators + .get(el.start_element.name) + .and_then(|evaluator| match evaluator.is_removal(&el.start_element) { + true => create(el, &self.remove_strategies), + false => None, + }) + .and_then(|(range, closed_range)| { + if !range.is_empty() { + Some((range, closed_range)) + } else { + None + } + }) + }; + + let child_markers = self.build_remove_marker(&el.children); + + if let Some((mut marker, pair)) = marker { + let mut start_cursor = 0; + for (child_marker, _) in &child_markers { + if marker.contains(&child_marker.start) + || marker.contains(&child_marker.end) { - end_marker = end_marker.start.min(child_marker.start) - ..end_marker.end.max(child_marker.end) + marker = marker.start.min(child_marker.start) + ..marker.end.max(child_marker.end) } else { break; } - end_cursor -= 1; + start_cursor += 1; } - let current = acc.len(); - acc.push(( - marker, - Some(current + (end_cursor - start_cursor).max(0) + 1), - )); - if start_cursor < end_cursor { - acc.extend(child_markers[start_cursor..end_cursor].to_owned()); + if let Some(mut end_marker) = pair { + let mut end_cursor = child_markers.len(); + for (child_marker, _) in child_markers.iter().rev() { + if end_marker.contains(&child_marker.start) + || end_marker.contains(&child_marker.end) + { + end_marker = end_marker.start.min(child_marker.start) + ..end_marker.end.max(child_marker.end) + } else { + break; + } + end_cursor -= 1; + } + + let current = acc.len(); + acc.push(( + marker, + Some(current + (end_cursor - start_cursor).max(0) + 1), + )); + if start_cursor < end_cursor { + acc.extend(child_markers[start_cursor..end_cursor].to_owned()); + } + acc.push((end_marker, Some(current))); + } else { + acc.push((marker, None)); } - acc.push((end_marker, Some(current))); } else { - acc.push((marker, None)); + acc.extend(child_markers); } - } else { - acc.extend(child_markers); } - } - acc - }) + acc + }) + } +} + +pub fn get_removed_pos(markers: &[RemoveMarker]) -> Vec { + markers + .iter() + .fold( + (vec![], 0), + |(mut positions, mut removed_len), (marker, pair_pos)| { + positions.push((marker.start - removed_len, *pair_pos)); + removed_len += marker.end - marker.start; + (positions, removed_len) + }, + ) + .0 } fn is_skip(el: &Element) -> bool { @@ -123,6 +131,7 @@ fn is_skip(el: &Element) -> bool { #[cfg(test)] mod tests { + use rstest::rstest; use std::rc::Rc; use marker::{ @@ -153,109 +162,93 @@ mod tests { ] } - #[test] - fn test_remove_marker() { - let mut builder_map: HashMap<&str, Box> = HashMap::new(); - builder_map.insert( - "tl", + fn initialize_removal_evaluators() -> RemovalEvaluators { + let mut removal_evaluators: RemovalEvaluators = HashMap::new(); + removal_evaluators.insert( + String::from("tl"), Box::new(TimeLimitedEvaluator { current_time: chrono::Local::now(), time_offset: "+00:00".to_string(), }), ); - // 0 1 2 3 4 - // byte_pos: 012345678901234567890123456789012-5678901234 - let content = Rc::new("foofuga".to_string()); - let tokens = tokenizer::tokenize(&content, "<", ">"); - let contents = parser::parse(&tokens); - assert_eq!( - build_remove_marker( - &contents, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)) - ), - vec![(3..40, None)] - ); - let content = Rc::new("fooa".to_string()); - let tokens = tokenizer::tokenize(&content, "<", ">"); - let contents = parser::parse(&tokens); - assert_eq!( - build_remove_marker( - &contents, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)) - ), - vec![] - ); + removal_evaluators } - #[test] - fn test_remove() { - let mut builder_map: HashMap<&str, Box> = HashMap::new(); - builder_map.insert( - "time-limited", - Box::new(TimeLimitedEvaluator { - current_time: chrono::Local::now(), - time_offset: "+00:00".to_string(), - }), - ); - builder_map.insert( - "tl", + #[rstest] + // 0 1 2 3 4 + // 012345678901234567890123456789012-5678901234 + #[case("foofuga", vec![(3..40, None)])] + #[case("fooa", vec![])] + fn test_remove_marker(#[case] content: &str, #[case] expected: Vec) { + let mut removal_evaluators: RemovalEvaluators = HashMap::new(); + removal_evaluators.insert( + String::from("tl"), Box::new(TimeLimitedEvaluator { current_time: chrono::Local::now(), time_offset: "+00:00".to_string(), }), ); + let tokens = tokenizer::tokenize(content, "<", ">"); + let contents = parser::parse(&tokens); + let content = Rc::new(content.to_string()); + let remover = Remover::new(removal_evaluators, initialize_remove_strategy(content)); + assert_eq!(remover.build_remove_marker(&contents), expected); + } + #[test] + fn test_remove() { let content = Rc::new( "
hoge - +

Campaign 1

- + foo bar baz - +

Campaign 2

- +
" .to_string(), ); - let (removed, markers) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, markers) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!( removed, "+
+ hoge+ + foo+ bar+ baz+ +
+".replace('+', "\n") ); - assert_eq!(markers, vec![(20..117, None), (146..243, None)]); + assert_eq!(markers, vec![(20..97, None), (126..203, None)]); let content = Rc::new( " hoge - +

Campaign 1

- + foo - +

Campaign 2

- + " .to_string(), ); - - let (removed, markers) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, markers) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!( removed, @@ -267,44 +260,46 @@ foo " .to_string() ); - assert_eq!(markers, vec![(6..95, None), (100..189, None),]); + assert_eq!(markers, vec![(6..75, None), (80..149, None),]); let content = Rc::new( " - +

Campaign 1

- + " .to_string(), ); - - let (removed, _) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, _) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!(removed, *content); let content = Rc::new( " // --- start --- -/* time-limited to='2021-12-31 23:50:00' unwrap-block */ +/* tl to='2021-12-31 23:50:00' unwrap-block */ if (foo) { console.log('abc'); console.log('def'); } -/* /time-limited */ +/* /tl */ // --- end --- " .to_string(), ); - - let (removed, markers) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, markers) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "/*", "*/")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!( removed, @@ -318,17 +313,19 @@ if (foo) { " .to_string() ); - assert_eq!(markers, vec![(18..85, Some(1)), (134..155, Some(0))]); + assert_eq!(markers, vec![(18..75, Some(1)), (124..135, Some(0))]); // byte_pos: 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567 // <-------------------------------------> <------------------------------------------> <-----> <-------------------------------------> let content = Rc::new("foo++bar+++{+ s1+ s2+}+++bar+".replace("+", "\n")); - let (removed, markers) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, markers) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "<", ">")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!(removed, "foo+++ s1+ s2++".to_string().replace("+", "\n")); assert_eq!( @@ -345,11 +342,13 @@ if (foo) { // 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123 // <-------------------------------------> <------------------------------------------> <-----------------------------------------> <-----> let content = Rc::new("foo++bar+++{+ s1+ + bar+ + s2+}+".replace("+", "\n")); - let (removed, markers) = remove( + let remover = Remover::new( + initialize_removal_evaluators(), + initialize_remove_strategy(Rc::clone(&content)), + ); + let (removed, markers) = remover.remove( parser::parse(&tokenizer::tokenize(&content, "<", ">")), &content, - &builder_map, - &initialize_remove_strategy(Rc::clone(&content)), ); assert_eq!( removed, diff --git a/src/main.rs b/src/main.rs index 930f0a5..1e2f65e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,10 @@ struct Args { /// Name of removal-marker to be removed #[arg(long, default_value = "vec![]")] removal_marker_target_name: Vec, + + /// List source code to be removed + #[arg(short, long)] + list: bool, } fn main() { @@ -73,8 +77,6 @@ fn main() { let marker_removal_tags = HashSet::from_iter(args.removal_marker_target_name); let config = ChiritoriConfiguration { - delimiter_start: args.delimiter_start, - delimiter_end: args.delimiter_end, time_limited_configuration: TimeLimitedConfiguration { tag_name: args.time_limited_tag_name, time_offset: args.time_limited_time_offset, @@ -89,13 +91,17 @@ fn main() { }, }; - let cleaned = chiritori::clean(content, config); + let output = if args.list { + chiritori::list(content, (args.delimiter_start, args.delimiter_end), config) + } else { + chiritori::clean(content, (args.delimiter_start, args.delimiter_end), config) + }; - if let Some(output) = args.output { - let mut f = File::create(output).expect("file not found"); - f.write_all(cleaned.as_bytes()) + if let Some(filename) = args.output { + let mut f = File::create(filename).expect("file not found"); + f.write_all(output.as_bytes()) .expect("something went wrong writing the file"); } else { - print!("{}", cleaned); + print!("{}", output); } }