From 0edff2a60275fc69a80f148ff9afd015a2c67e2d Mon Sep 17 00:00:00 2001 From: piyoppi Date: Thu, 21 Nov 2024 23:38:59 +0900 Subject: [PATCH] Add removal-marker-target-config option --- src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2f86690..1471c00 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use chiritori::{ChiritoriConfiguration, MarkerTagConfiguration, TimeLimitedConfi use clap::Parser; use std::collections::HashSet; use std::fs::File; -use std::io::prelude::*; +use std::io::{prelude::*, BufReader}; use std::rc::Rc; mod chiritori; mod code; @@ -49,6 +49,11 @@ struct Args { #[arg(long, default_value = "vec![]")] removal_marker_target_name: Vec, + /// Config file specifying the name of the removal-marker to be removed. + /// The content of the config file is indicated by the name of the removal target, separated by a newline. + #[arg(long)] + removal_marker_target_config: Option, + /// List source code to be removed #[arg(short, long)] list: bool, @@ -77,8 +82,16 @@ fn main() { .expect("something went wrong reading the file"); } - let content = Rc::new(content); - let marker_removal_tags = HashSet::from_iter(args.removal_marker_target_name); + let removal_marker_target_names_from_file = if let Some(removal_marker_target_config) = args.removal_marker_target_config { + let f = File::open(removal_marker_target_config).expect("file not found"); + let reader = BufReader::new(f); + + reader.lines().map_while(Result::ok).collect::>() + } else { + vec![] + }; + + let marker_removal_tags: HashSet<_> = removal_marker_target_names_from_file.into_iter().chain(args.removal_marker_target_name).collect(); let config = ChiritoriConfiguration { time_limited_configuration: TimeLimitedConfiguration { @@ -95,6 +108,8 @@ fn main() { }, }; + let content = Rc::new(content); + let output = if args.list { chiritori::list(content, (args.delimiter_start, args.delimiter_end), config) } else if args.list_all {