diff --git a/examples/images-in-downloads.json b/examples/images-in-downloads.json new file mode 100644 index 0000000..81ece11 --- /dev/null +++ b/examples/images-in-downloads.json @@ -0,0 +1,13 @@ +[ + { + "filter": { + "type": "all", "filters": [ + {"type": "content_type", "mime": "image/png"} + ] + }, + "location": "~/Downloads", + "actions": [ + "trash" + ] + } +] diff --git a/src/main.rs b/src/main.rs index 51eb8fc..48d4f0a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,41 +2,37 @@ use color_eyre::eyre::Result; use futures::prelude::*; use clap::Parser; +use std::io::Read; + mod filters; mod job; mod pattern; mod actions; -const DATA: &str = r#" -[ - { - "filter": { - "type": "all", "filters": [ - {"type": "content_type", "bytes": [137, 80, 78, 71]} - ] - }, - "location": "~/Downloads", - "actions": [ - {"move": "~/test"} - ] - } -]"#; - #[derive(Debug, Parser)] struct Args { spec: Option, /// Run specified commands instead of printing them - #[arg(long, short)] + #[arg(long = "no-dry-run", short = '!')] execute: bool, } +impl Args { + fn data(&self) -> std::io::Result> { + Ok(match self.spec { + Some(ref path) => Box::new(std::fs::File::open(path)?), + None => Box::new(std::io::stdin()), + }) + } +} + #[tokio::main] async fn main() -> Result<()> { let args = Args::parse(); - println!("{args:#?}"); + let reader = args.data()?; - let jobs: Vec = serde_json::from_str(DATA).unwrap(); + let jobs: Vec = serde_json::from_reader(reader)?; stream::iter(&jobs) .then(|job| job.actions())