// 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, /// 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> { 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 = 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(()) }