commit a47f0ba1b2914e6aa2d04bcca5d82fe728b32ce3 parent c5634dac9134f7574e8894295d5ed05f7439b312 Author: William Casarin <jb55@jb55.com> Date: Mon, 10 Jun 2024 07:52:17 -0700 args: allow filter files and raw filters on cli Signed-off-by: William Casarin <jb55@jb55.com> Diffstat:
M | src/app.rs | | | 37 | +++++++++++++++++++++++++++++++++++-- |
1 file changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/app.rs b/src/app.rs @@ -635,13 +635,46 @@ impl Damus { ) -> Self { let mut timelines: Vec<Timeline> = vec![]; let mut is_mobile: Option<bool> = None; + let mut i = 0; + if args.len() > 1 { for arg in &args[1..] { if arg == "--mobile" { is_mobile = Some(true); - } else if let Ok(filter) = serde_json::from_str(arg) { - timelines.push(Timeline::new(filter)); + } else if arg == "--filter" { + let next_args = &args[1 + i + 1..]; + if next_args.len() == 0 { + continue; + } + let filter = &next_args[0]; + + if let Ok(filter) = serde_json::from_str(filter) { + timelines.push(Timeline::new(filter)); + } else { + error!("failed to parse filter '{}'", filter); + } + } else if arg == "--filter-file" || arg == "-f" { + let next_args = &args[1 + i + 1..]; + if next_args.len() == 0 { + continue; + } + let filter_file = &next_args[0]; + + let data = if let Ok(data) = std::fs::read(filter_file) { + data + } else { + error!("failed to read filter file '{}'", filter_file); + continue; + }; + + if let Ok(filter) = serde_json::from_slice(&data) { + timelines.push(Timeline::new(filter)); + } else { + error!("failed to parse filter in '{}'", filter_file); + } } + + i += 1; } } else { let filter = serde_json::from_str(include_str!("../queries/timeline.json")).unwrap();