Simple tool for automatic file management
1use color_eyre::eyre::Result; 2use futures::prelude::*; 3use clap::Parser; 4 5mod filters; 6mod job; 7mod pattern; 8mod actions; 9 10const DATA: &str = r#" 11[ 12 { 13 "filter": { 14 "type": "all", "filters": [ 15 {"type": "content_type", "bytes": [137, 80, 78, 71]} 16 ] 17 }, 18 "location": "~/Downloads", 19 "actions": [ 20 {"move": "~/test"} 21 ] 22 } 23]"#; 24 25#[derive(Debug, Parser)] 26struct Args { 27 spec: Option<std::path::PathBuf>, 28 /// Run specified commands instead of printing them 29 #[arg(long, short)] 30 execute: bool, 31} 32 33#[tokio::main] 34async fn main() -> Result<()> { 35 let args = Args::parse(); 36 37 println!("{args:#?}"); 38 39 let jobs: Vec<job::Job> = serde_json::from_str(DATA).unwrap(); 40 41 stream::iter(&jobs) 42 .then(|job| job.actions()) 43 .map(|result| result.unwrap()) 44 .flatten() 45 .for_each_concurrent(None, |(action, path)| action.run(path, args.execute)) 46 .await; 47 48 Ok(()) 49}