Simple tool for automatic file management

ft: always print which action took place

hauleth.dev c783ad36 5064df15

verified
Changed files
+11 -7
examples
src
+2 -1
examples/downloaded-gp-to-guitar.json
···
"filter": {
"type": "any",
"filters": [
-
{"type": "name", "wildcard": "*.gp"}
+
{"type": "name", "wildcard": "*.gp"},
+
{"type": "name", "wildcard": "*.gp5"}
]
},
"actions": [
+3 -3
src/actions.rs
···
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:?}"),
+6 -3
src/main.rs
···
/// 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<Box<dyn Read>> {
+
fn data(&self) -> Result<Box<dyn Read>> {
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!(),
})
}
}