2024-05-29 21:42:18 -04:00
|
|
|
// src/main.rs
|
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
mod cli;
|
2024-05-30 14:50:34 -04:00
|
|
|
mod manip;
|
2024-05-29 21:42:18 -04:00
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
use glob::glob;
|
|
|
|
use manip::{Limit, LimitList, MergedLimitList};
|
2024-05-30 20:59:22 -04:00
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
fn main() -> std::io::Result<()> {
|
2024-06-03 02:24:43 -04:00
|
|
|
env_logger::init(); // TODO add more logging & actual error handling
|
2024-05-30 18:48:17 -04:00
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
// TODO utilize CLI
|
|
|
|
// let _cli = cli::Cli::parse();
|
2024-05-30 20:59:22 -04:00
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
// TODO parse config file if one is provided
|
2024-05-30 20:59:22 -04:00
|
|
|
|
2024-06-03 00:56:42 -04:00
|
|
|
let mut merged_list = MergedLimitList::new();
|
2024-05-31 01:21:27 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
// Crawl /suspend for suspend lists -> glob pattern: "suspend/**/*.txt"
|
2024-06-03 00:56:42 -04:00
|
|
|
{
|
2024-06-03 02:24:43 -04:00
|
|
|
let mut suspend_lists = vec![];
|
|
|
|
let suspend_paths = glob("suspend/**/*.txt").expect("Bad glob pattern");
|
2024-06-02 02:24:54 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
for path in suspend_paths.filter_map(|x| x.ok()) {
|
|
|
|
suspend_lists.extend(LimitList::from_file(path));
|
2024-06-03 00:56:42 -04:00
|
|
|
// TODO Check if path contains trust value as part of filename when building limitlist
|
|
|
|
}
|
2024-05-31 01:21:27 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
for list in suspend_lists {
|
|
|
|
merged_list.add_limit_list(list, Limit::Suspend);
|
2024-06-03 00:56:42 -04:00
|
|
|
}
|
|
|
|
}
|
2024-05-30 18:48:17 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
// Crawl /silence for silence lists -> glob pattern: "silence/**/*.txt"
|
2024-06-03 00:56:42 -04:00
|
|
|
{
|
2024-06-03 02:24:43 -04:00
|
|
|
let mut silence_lists = vec![];
|
|
|
|
let silence_paths = glob("silence/**/*.txt").expect("Bad glob pattern");
|
2024-05-31 01:21:27 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
for path in silence_paths.filter_map(|x| x.ok()) {
|
|
|
|
silence_lists.extend(LimitList::from_file(path));
|
2024-06-03 00:56:42 -04:00
|
|
|
// TODO Check if path contains trust value as part of filename when building limitlist
|
|
|
|
}
|
2024-05-30 20:59:22 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
for list in silence_lists {
|
2024-06-03 00:56:42 -04:00
|
|
|
merged_list.add_limit_list(list, Limit::Silence);
|
|
|
|
}
|
2024-05-31 01:21:27 -04:00
|
|
|
}
|
2024-05-31 03:13:02 -04:00
|
|
|
|
2024-06-03 02:24:43 -04:00
|
|
|
merged_list.export_file("suspend.txt", "silence.txt", (50, 33))
|
2024-05-30 20:59:22 -04:00
|
|
|
}
|