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!(), }) } }