Simple tool for automatic file management

ft: add basic options parsing

hauleth.dev 2784a34e ef186dd2

verified
Changed files
+149 -11
src
+124 -2
Cargo.lock
···
]
[[package]]
+
name = "anstream"
+
version = "0.6.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "4cd2405b3ac1faab2990b74d728624cd9fd115651fcecc7c2d8daf01376275ba"
+
dependencies = [
+
"anstyle",
+
"anstyle-parse",
+
"anstyle-query",
+
"anstyle-wincon",
+
"colorchoice",
+
"utf8parse",
+
]
+
+
[[package]]
+
name = "anstyle"
+
version = "1.0.4"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
+
+
[[package]]
+
name = "anstyle-parse"
+
version = "0.2.3"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
+
dependencies = [
+
"utf8parse",
+
]
+
+
[[package]]
+
name = "anstyle-query"
+
version = "1.0.2"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
+
dependencies = [
+
"windows-sys 0.52.0",
+
]
+
+
[[package]]
+
name = "anstyle-wincon"
+
version = "3.0.2"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
+
dependencies = [
+
"anstyle",
+
"windows-sys 0.52.0",
+
]
+
+
[[package]]
name = "async-stream"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
]
[[package]]
+
name = "clap"
+
version = "4.4.16"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "58e54881c004cec7895b0068a0a954cd5d62da01aef83fa35b1e594497bf5445"
+
dependencies = [
+
"clap_builder",
+
"clap_derive",
+
]
+
+
[[package]]
+
name = "clap_builder"
+
version = "4.4.16"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "59cb82d7f531603d2fd1f507441cdd35184fa81beff7bd489570de7f773460bb"
+
dependencies = [
+
"anstream",
+
"anstyle",
+
"clap_lex",
+
"strsim",
+
]
+
+
[[package]]
+
name = "clap_derive"
+
version = "4.4.7"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
+
dependencies = [
+
"heck",
+
"proc-macro2",
+
"quote",
+
"syn",
+
]
+
+
[[package]]
+
name = "clap_lex"
+
version = "0.6.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
+
+
[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
"tracing-core",
"tracing-error",
]
+
+
[[package]]
+
name = "colorchoice"
+
version = "1.0.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "core-foundation-sys"
···
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
+
name = "heck"
+
version = "0.4.1"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
+
+
[[package]]
name = "hermit-abi"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
dependencies = [
"libc",
"wasi",
-
"windows-sys",
+
"windows-sys 0.48.0",
]
[[package]]
···
dependencies = [
"async-stream",
"async-trait",
+
"clap",
"color-eyre",
"futures",
"libc",
···
checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970"
[[package]]
+
name = "strsim"
+
version = "0.10.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
+
+
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
-
"windows-sys",
+
"windows-sys 0.48.0",
]
[[package]]
···
]
[[package]]
+
name = "utf8parse"
+
version = "0.2.1"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
+
+
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
···
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
+
]
+
+
[[package]]
+
name = "windows-sys"
+
version = "0.52.0"
+
source = "registry+https://github.com/rust-lang/crates.io-index"
+
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
+
dependencies = [
+
"windows-targets 0.52.0",
]
[[package]]
+1
Cargo.toml
···
[dependencies]
async-stream = "0.3.5"
async-trait = "0.1.77"
+
clap = { version = "4.4.16", features = ["derive"] }
color-eyre = "0.6.2"
futures = "0.3.30"
libc = "0.2.152"
+24 -9
src/main.rs
···
use color_eyre::eyre::Result;
-
use tokio_stream::iter;
-
use futures::StreamExt;
+
use futures::prelude::*;
+
use clap::Parser;
mod filters;
mod job;
mod pattern;
+
mod actions;
const DATA: &str = r#"
[
{
-
"filters": [
-
{"type": "name", "Wildcard": "*.dmg"}
-
],
+
"filter": {
+
"type": "all", "filters": [
+
{"type": "content_type", "bytes": [137, 80, 78, 71]}
+
]
+
},
"location": "~/Downloads",
"actions": [
-
{"message": "move to ~/Documents/Gitara/"}
+
{"move": "~/test"}
]
}
]"#;
+
#[derive(Debug, Parser)]
+
struct Args {
+
spec: Option<std::path::PathBuf>,
+
/// Run specified commands instead of printing them
+
#[arg(long, short)]
+
execute: bool,
+
}
+
#[tokio::main]
async fn main() -> Result<()> {
+
let args = Args::parse();
+
+
println!("{args:#?}");
+
let jobs: Vec<job::Job> = serde_json::from_str(DATA).unwrap();
-
iter(&jobs)
-
.then(|job| job.run())
+
stream::iter(&jobs)
+
.then(|job| job.actions())
.map(|result| result.unwrap())
.flatten()
-
.for_each_concurrent(None, |(action, path)| action.execute(path))
+
.for_each_concurrent(None, |(action, path)| action.run(path, args.execute))
.await;
Ok(())