From c783ad36df30436c7198d96c4ad5ed2ef50a5cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Niemier?= Date: Tue, 16 Jan 2024 10:45:19 +0100 Subject: [PATCH] ft: always print which action took place --- examples/downloaded-gp-to-guitar.json | 3 ++- src/actions.rs | 6 +++--- src/main.rs | 9 ++++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/downloaded-gp-to-guitar.json b/examples/downloaded-gp-to-guitar.json index b3f2e23..e3482cf 100644 --- a/examples/downloaded-gp-to-guitar.json +++ b/examples/downloaded-gp-to-guitar.json @@ -4,7 +4,8 @@ "filter": { "type": "any", "filters": [ - {"type": "name", "wildcard": "*.gp"} + {"type": "name", "wildcard": "*.gp"}, + {"type": "name", "wildcard": "*.gp5"} ] }, "actions": [ diff --git a/src/actions.rs b/src/actions.rs index c8b7e9e..ad69445 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -21,14 +21,14 @@ pub enum Action { impl Action { pub async fn run(self, source: PathBuf, execute: bool) { + self.dry_run(&source).await; + if execute { self.execute(source).await - } else { - self.dry_run(source).await } } - pub async fn dry_run(self, source: PathBuf) { + pub async fn dry_run(&self, source: &Path) { match self { Action::Script(ref script) => println!("Execute {script:?} {source:?}"), Action::Move(ref dest) => println!("Move {source:?} -> {dest:?}"), diff --git a/src/main.rs b/src/main.rs index 07fed53..80efa96 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,13 +15,16 @@ struct Args { /// Run specified commands instead of printing them #[arg(long = "no-dry-run", short = '!')] execute: bool, + #[arg(long)] + stdin: bool, } impl Args { - fn data(&self) -> std::io::Result> { + fn data(&self) -> Result> { Ok(match self.spec { - Some(ref path) => Box::new(std::fs::File::open(path)?), - None => Box::new(std::io::stdin()), + Some(ref path) if !self.stdin => Box::new(std::fs::File::open(path)?), + None if self.stdin => Box::new(std::io::stdin()), + _ => unimplemented!(), }) } } -- 2.51.2