Something went wrong. Try again.
Simple tool for automatic file management
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// SPDX-FileCopyrightText: 2024 Łukasz Niemier <#@hauleth.dev>//// SPDX-License-Identifier: EUPL-1.2
use clap::Parser;use color_eyre::eyre::Result;use futures::prelude::*;
use std::io::Read;
mod actions;mod filters;mod job;mod pattern;
#[derive(Debug, Parser)]struct Args { spec: Option<std::path::PathBuf>, /// Run specified commands instead of printing them #[arg(long = "no-dry-run", short = '!')] execute: bool, #[arg(long)] stdin: bool,}
impl Args { fn data(&self) -> Result<Box<dyn Read>> { Ok(match self.spec { Some(ref path) if !self.stdin => Box::new(std::fs::File::open(path)?), None if self.stdin => Box::new(std::io::stdin()), _ => unimplemented!(), }) }}
#[tokio::main]async fn main() -> Result<()> { let args = Args::parse();
let reader = args.data()?;
let jobs: Vec<job::Job> = serde_json::from_reader(reader)?;
let tasks: Vec<_> = stream::iter(&jobs) .then(|job| job.actions()) .try_collect() .await?;
if !args.execute { println!("Dry run, to apply changes run with flag `-!`\n"); }
//let out = stream::iter(tasks) .flatten() .then(|(action, path)| action.run(path, args.execute)) .count() .await;
Ok(())}