From 1091399fec9d6f3c911a230e19c320f2831c65e1 Mon Sep 17 00:00:00 2001 From: gil Date: Thu, 30 May 2024 17:48:17 -0500 Subject: [PATCH] Add clap, relocate test blocklists --- Cargo.lock | 88 +++++++++++++++++++ Cargo.toml | 1 + README.md | 2 +- src/main.rs | 15 +++- src/manip.rs | 5 +- src/tests/manip.rs | 22 ++--- .../example_blocklist.txt | 0 .../example_mutelist.txt | 0 test_blocks.txt => test/test_blocks.txt | 0 test_mutes.txt => test/test_mutes.txt | 0 10 files changed, 115 insertions(+), 18 deletions(-) rename example_blocklist1.txt => test/example_blocklist.txt (100%) rename example_mutelist1.txt => test/example_mutelist.txt (100%) rename test_blocks.txt => test/test_blocks.txt (100%) rename test_mutes.txt => test/test_mutes.txt (100%) diff --git a/Cargo.lock b/Cargo.lock index 0a2b9ec..31b72ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -60,6 +60,46 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + [[package]] name = "colorchoice" version = "1.0.1" @@ -93,10 +133,17 @@ dependencies = [ name = "fediloom" version = "0.1.0" dependencies = [ + "clap", "env_logger", "log", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "humantime" version = "2.1.0" @@ -121,6 +168,24 @@ version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" +[[package]] +name = "proc-macro2" +version = "1.0.84" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + [[package]] name = "regex" version = "1.10.4" @@ -150,6 +215,29 @@ version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "utf8parse" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 33bc6a3..5709d2c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,6 @@ version = "0.1.0" edition = "2021" [dependencies] +clap = { version = "4.5.4", features = ["derive"] } env_logger = "0.11.3" log = "0.4.21" diff --git a/README.md b/README.md index b3f123b..39d5717 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ Goal - a commandline-based tool for creating blocklists for ActivityPub software - [ ] Use URLs as sources - [ ] Directly request lists from API endpoints - [ ] Create tiered or thresholded lists -- [ ] Support CSV and JSON1 \ No newline at end of file +- [ ] Support CSV and JSON \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 10336a1..001b284 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,9 +3,20 @@ mod manip; mod tests; +use clap::Parser; + +#[derive(Parser)] +struct Cli { + // TODO inputs + // TODO outputs + // TODO cfg file (TOML) + // TODO options + // TODO verbose mode + // +} + fn main() { println!("Hello, world!"); - // TODO argument parsing + // TODO argument parsing - IN PROGRESS // TODO logging - // TODO config file } \ No newline at end of file diff --git a/src/manip.rs b/src/manip.rs index c55dc28..e96481f 100644 --- a/src/manip.rs +++ b/src/manip.rs @@ -138,10 +138,7 @@ impl ModMap { } pub fn alphabetize_lines(string: String) -> String { - let mut v = string - .lines() - .map(|literal| literal.to_string()) - .collect::>(); + let mut v = string.lines().collect::>(); v.sort_by_key(|a| a.to_lowercase()); v.join("\n") + "\n" diff --git a/src/tests/manip.rs b/src/tests/manip.rs index f51f725..7d9f5b5 100644 --- a/src/tests/manip.rs +++ b/src/tests/manip.rs @@ -80,8 +80,8 @@ fn modsource_from_map_and_trust() { #[test] fn modsource_from_file() { let mut src = ModSource::default(); - src.import_file("example_blocklist1.txt", ModAction::Block) - .import_file("example_mutelist1.txt", ModAction::Silence); + src.import_file("test/example_blocklist.txt", ModAction::Block) + .import_file("test/example_mutelist.txt", ModAction::Silence); let test_src = ModSource::from(HashMap::from([ (String::from("example.com"), ModAction::Block), @@ -103,8 +103,8 @@ fn modmap_from_modsource() { ])); let mut src2 = ModSource::default(); - src2.import_file("example_blocklist1.txt", ModAction::Block) - .import_file("example_mutelist1.txt", ModAction::Silence); + src2.import_file("test/example_blocklist.txt", ModAction::Block) + .import_file("test/example_mutelist.txt", ModAction::Silence); ml.add_source(src1).add_source(src2); @@ -166,8 +166,8 @@ fn modmap_export_txt() { ])); let mut src2 = ModSource::default(); - src2.import_file("example_blocklist1.txt", ModAction::Block) - .import_file("example_mutelist1.txt", ModAction::Silence); + src2.import_file("test/example_blocklist.txt", ModAction::Block) + .import_file("test/example_mutelist.txt", ModAction::Silence); let src3 = ModSource::build( HashMap::from([ @@ -190,11 +190,11 @@ fn modmap_export_txt() { .add_source(src3) .add_source(src4); - let _ = ml.export_file("test_blocks.txt", "test_mutes.txt", (200, 150)); + let _ = ml.export_file("test/test_blocks.txt", "test/test_mutes.txt", (200, 150)); - let blocks: String = fs::read_to_string("test_blocks.txt").unwrap(); - let mutes: String = fs::read_to_string("test_mutes.txt").unwrap(); + let file_blocks: String = fs::read_to_string("test/test_blocks.txt").unwrap(); + let file_mutes: String = fs::read_to_string("test/test_mutes.txt").unwrap(); - assert_eq!(blocks, "example.com\n"); - assert_eq!(mutes, "example.net\nexample.org\n"); + assert_eq!(file_blocks, "example.com\n"); + assert_eq!(file_mutes, "example.net\nexample.org\n"); } diff --git a/example_blocklist1.txt b/test/example_blocklist.txt similarity index 100% rename from example_blocklist1.txt rename to test/example_blocklist.txt diff --git a/example_mutelist1.txt b/test/example_mutelist.txt similarity index 100% rename from example_mutelist1.txt rename to test/example_mutelist.txt diff --git a/test_blocks.txt b/test/test_blocks.txt similarity index 100% rename from test_blocks.txt rename to test/test_blocks.txt diff --git a/test_mutes.txt b/test/test_mutes.txt similarity index 100% rename from test_mutes.txt rename to test/test_mutes.txt