Implement keywords_file option

Signed-off-by: hr567 <hr567@hr567.me>
This commit is contained in:
hr567 2024-06-03 16:49:25 +08:00
parent 1727bd8e6e
commit caafa8f715
Signed by: hr567
SSH Key Fingerprint: SHA256:AUrHz/3TKmc6tf4wqaaEPV/BGQ4aULSp7g76FpqujYw

View File

@ -30,7 +30,14 @@ struct Args {
keywords: Vec<String>,
}
static ARGS: Lazy<Args> = Lazy::new(Args::parse);
static ARGS: Lazy<Args> = Lazy::new(|| {
let mut args = Args::parse();
if let Some(keywords_file) = args.keywords_file.take() {
let content = std::fs::read_to_string(keywords_file).expect("failed to read keywords file");
args.keywords.extend(content.lines().map(|s| s.to_string()));
}
args
});
thread_local! {
static ANALYZER: OnceCell<AhoCorasick> = const { OnceCell::new() };
}