From 77d2ac94534b12300b5b7eff6e28023d815708eb Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 4 Apr 2023 20:50:09 +0200 Subject: add clap & cargo update --- Cargo.lock | 614 +++++++++++++++++++++++++++++++++++++++++++------------------ Cargo.toml | 5 +- 2 files changed, 443 insertions(+), 176 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fc25ffa..5638eb6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,46 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-wincon", + "concolor-override", + "concolor-query", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" + +[[package]] +name = "anstyle-parse" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-wincon" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +dependencies = [ + "anstyle", + "windows-sys 0.45.0", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -70,6 +110,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" + [[package]] name = "bumpalo" version = "3.12.0" @@ -96,9 +142,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.23" +version = "0.4.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16b0a3d9ed01224b22057780a37bb8c5dbfe1be8ba48678e7bf57ec4b385411f" +checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" dependencies = [ "iana-time-zone", "js-sys", @@ -109,6 +155,48 @@ dependencies = [ "winapi", ] +[[package]] +name = "clap" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +dependencies = [ + "anstream", + "anstyle", + "bitflags 1.3.2", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.13", +] + +[[package]] +name = "clap_lex" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" + [[package]] name = "codespan-reporting" version = "0.11.1" @@ -119,6 +207,21 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "concolor-override" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" + +[[package]] +name = "concolor-query" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" +dependencies = [ + "windows-sys 0.45.0", +] + [[package]] name = "core-foundation" version = "0.9.3" @@ -131,15 +234,15 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "cxx" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86d3488e7665a7a483b57e25bdd90d0aeb2bc7608c8d0346acf2ad3f1caf1d62" +checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" dependencies = [ "cc", "cxxbridge-flags", @@ -149,9 +252,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48fcaf066a053a41a81dfb14d57d99738b767febb8b735c3016e469fac5da690" +checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" dependencies = [ "cc", "codespan-reporting", @@ -159,44 +262,44 @@ dependencies = [ "proc-macro2", "quote", "scratch", - "syn", + "syn 2.0.13", ] [[package]] name = "cxxbridge-flags" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef98b8b717a829ca5603af80e1f9e2e48013ab227b68ef37872ef84ee479bf" +checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" [[package]] name = "cxxbridge-macro" -version = "1.0.91" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "086c685979a698443656e5cf7856c95c642295a38599f12fb1ff76fb28d19892" +checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "dirs" -version = "4.0.0" +version = "5.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3aa72a6f96ea37bbc5aa912f6788242832f75369bdfdadcb0e38423f100059" +checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.3.7" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b" dependencies = [ "libc", "redox_users", - "winapi", + "windows-sys 0.45.0", ] [[package]] @@ -208,6 +311,27 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "errno" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "error-chain" version = "0.12.4" @@ -271,53 +395,53 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" +checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" +checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" [[package]] name = "futures-io" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" +checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" [[package]] name = "futures-macro" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" +checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "futures-sink" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" +checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" [[package]] name = "futures-task" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" +checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" [[package]] name = "futures-util" -version = "0.3.26" +version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" +checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ "futures-core", "futures-io", @@ -349,9 +473,9 @@ checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "h2" -version = "0.3.15" +version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f29bc9dda355256b2916cf526ab02ce0aeaaaf2bad60d65ef3f12f11dd0f4" +checksum = "5be7b54589b581f624f566bf5d8eb2bab1db736c51528720b6bd36b96b55924d" dependencies = [ "bytes", "fnv", @@ -384,6 +508,12 @@ dependencies = [ "hashbrown", ] +[[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.2.6" @@ -393,6 +523,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "http" version = "0.2.9" @@ -429,9 +565,9 @@ checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" [[package]] name = "hyper" -version = "0.14.24" +version = "0.14.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e011372fa0b68db8350aa7a248930ecc7839bf46d8485577d69f117a75f164c" +checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" dependencies = [ "bytes", "futures-channel", @@ -466,16 +602,16 @@ dependencies = [ [[package]] name = "iana-time-zone" -version = "0.1.53" +version = "0.1.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64c122667b287044802d6ce17ee2ddf13207ed924c712de9a66a5814d5b64765" +checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "winapi", + "windows", ] [[package]] @@ -500,9 +636,9 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.9.2" +version = "1.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", "hashbrown", @@ -517,17 +653,40 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "io-lifetimes" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09270fd4fa1111bc614ed2246c7ef56239a3063d5be0d1ec3b589c505d400aeb" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.45.0", +] + [[package]] name = "ipnet" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30e22bd8629359895450b59ea7a776c850561b96a3b1d31321c1949d9e6c9146" +checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" + +[[package]] +name = "is-terminal" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "256017f749ab3117e93acb91063009e1f1bb56d03965b14c2c8df4eb02c524d8" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] [[package]] name = "itoa" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fad582f4b9e86b6caa621cabeb0963332d92eea04729ab12892c2533951e6440" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" @@ -546,15 +705,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.139" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "libsqlite3-sys" -version = "0.25.2" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f835d03d717946d28b1d1ed632eb6f0e24a299388ee623d0c23118d3e8a7fa" +checksum = "afc22eff61b133b115c6e8c74e818c628d6d5e7a502afea6f64dee076dd94326" dependencies = [ "cc", "pkg-config", @@ -570,6 +729,12 @@ dependencies = [ "cc", ] +[[package]] +name = "linux-raw-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" + [[package]] name = "lock_api" version = "0.4.9" @@ -597,9 +762,9 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mime" -version = "0.3.16" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" [[package]] name = "miniz_oxide" @@ -624,9 +789,10 @@ dependencies = [ [[package]] name = "modlist" -version = "0.11.0" +version = "0.11.1" dependencies = [ "chrono", + "clap", "dirs", "error-chain", "futures-util", @@ -656,15 +822,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "nom8" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae01545c9c7fc4486ab7debaf2aad7003ac19431791868fb2e8066df97fad2f8" -dependencies = [ - "memchr", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -690,7 +847,7 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ - "hermit-abi", + "hermit-abi 0.2.6", "libc", ] @@ -711,11 +868,11 @@ checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" [[package]] name = "openssl" -version = "0.10.45" +version = "0.10.49" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" +checksum = "4d2f106ab837a24e03672c59b1239669a0596406ff657c3c0835b6b7f0f35a33" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "foreign-types", "libc", @@ -726,13 +883,13 @@ dependencies = [ [[package]] name = "openssl-macros" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -743,11 +900,10 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.80" +version = "0.9.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" +checksum = "3a20eace9dc2d82904039cb76dcf50fb1a0bba071cfd1629720b5d6f1ddba0fa" dependencies = [ - "autocfg", "cc", "libc", "pkg-config", @@ -772,7 +928,7 @@ checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.2.16", "smallvec", "windows-sys 0.45.0", ] @@ -803,18 +959,18 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "proc-macro2" -version = "1.0.51" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" dependencies = [ "proc-macro2", ] @@ -825,34 +981,34 @@ version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] -name = "redox_users" -version = "0.4.3" +name = "redox_syscall" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "getrandom", - "redox_syscall", - "thiserror", + "bitflags 1.3.2", ] [[package]] -name = "remove_dir_all" -version = "0.5.3" +name = "redox_users" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" dependencies = [ - "winapi", + "getrandom", + "redox_syscall 0.2.16", + "thiserror", ] [[package]] name = "reqwest" -version = "0.11.14" +version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21eed90ec8570952d53b772ecf8f206aa1ec9a3d76b2521c56c42973f2d91ee9" +checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" dependencies = [ "base64", "bytes", @@ -889,11 +1045,11 @@ dependencies = [ [[package]] name = "rusqlite" -version = "0.28.0" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" +checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2" dependencies = [ - "bitflags", + "bitflags 2.0.2", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -903,15 +1059,29 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" + +[[package]] +name = "rustix" +version = "0.37.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] [[package]] name = "ryu" -version = "1.0.12" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4b9743ed687d4b4bcedf9ff5eaa7398495ae14e61cba0a295704edbc7decde" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "schannel" @@ -930,9 +1100,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "scratch" -version = "1.0.3" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddccb15bcce173023b3fedd9436f882a0739b8dfb45e4f6b6002bee5929f61b2" +checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] name = "security-framework" @@ -940,7 +1110,7 @@ version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -959,29 +1129,29 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.152" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.152" +version = "1.0.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] name = "serde_json" -version = "1.0.93" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad406b69c91885b5107daf2c29572f6c8cdb3c66826821e286c533490c0bc76" +checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" dependencies = [ "itoa", "ryu", @@ -1020,9 +1190,9 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.7" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" dependencies = [ "autocfg", ] @@ -1035,19 +1205,36 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", "winapi", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" -version = "1.0.107" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c9da457c5285ac1f936ebd076af6dac17a61cfe7826f2076b4d015cf47bc8ec" dependencies = [ "proc-macro2", "quote", @@ -1056,16 +1243,15 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.3.0" +version = "3.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" dependencies = [ "cfg-if", "fastrand", - "libc", - "redox_syscall", - "remove_dir_all", - "winapi", + "redox_syscall 0.3.5", + "rustix", + "windows-sys 0.45.0", ] [[package]] @@ -1079,22 +1265,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a9cd18aa97d5c45c6603caea1da6628790b37f7a34b6ca89522331c5180fed0" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.38" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fb327af4685e4d03fa8cbcf1716380da910eeb2bb8be417e7f9fd3fb164f36f" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -1125,14 +1311,13 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.25.0" +version = "1.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" +checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" dependencies = [ "autocfg", "bytes", "libc", - "memchr", "mio", "num_cpus", "parking_lot", @@ -1140,18 +1325,18 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.42.0", + "windows-sys 0.45.0", ] [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.13", ] [[package]] @@ -1180,9 +1365,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7afcae9e3f0fe2c370fd4657108972cbb2fa9db1b9f84849cefd80741b01cb6" +checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21" dependencies = [ "serde", "serde_spanned", @@ -1201,15 +1386,15 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.19.3" +version = "0.19.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e6a7712b49e1775fb9a7b998de6635b299237f48b404dde71704f2e0e7f37e5" +checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" dependencies = [ "indexmap", - "nom8", "serde", "serde_spanned", "toml_datetime", + "winnow", ] [[package]] @@ -1246,15 +1431,15 @@ checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" [[package]] name = "unicode-bidi" -version = "0.3.10" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.6" +version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" [[package]] name = "unicode-normalization" @@ -1282,6 +1467,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "vcpkg" version = "0.2.15" @@ -1337,7 +1528,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -1371,7 +1562,7 @@ checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1436,19 +1627,28 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", ] [[package]] @@ -1457,65 +1657,131 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", ] [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winnow" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +dependencies = [ + "memchr", +] [[package]] name = "winreg" diff --git a/Cargo.toml b/Cargo.toml index 7d55c00..1f5c1cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,9 +10,10 @@ reqwest = { version = "0.11", features = ["json", "stream"] } tokio = { version = "1", features = ["full"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.87" -rusqlite = { version = "0.28.0", features = ["bundled"] } +rusqlite = { version = "0.29.0", features = ["bundled"] } futures-util = "0.3.14" chrono = "0.4.22" toml = "0.7.2" error-chain = "0.12.4" -dirs = "4.0.0" +dirs = "5.0.0" +clap = { version = "4.2.1", features = ["derive"] } -- cgit v1.2.3 From 93e61a4bd6ad8b5db1083bdd21994bf73b0b90ba Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 17 Apr 2023 20:30:16 +0200 Subject: added clap cli, modified (basically) all user interface functions; changed some functions to easier string handling --- src/commands/download.rs | 12 +- src/commands/io.rs | 29 ++--- src/commands/list.rs | 53 +++------ src/commands/modification.rs | 44 +++---- src/commands/update.rs | 22 +--- src/config.rs | 2 +- src/db.rs | 10 +- src/lib.rs | 20 ++-- src/main.rs | 278 ++++++++++++++++++++++++++++++++++--------- 9 files changed, 289 insertions(+), 181 deletions(-) diff --git a/src/commands/download.rs b/src/commands/download.rs index 2714630..4baecee 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,10 +1,10 @@ use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version, clean_list_dir}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; -use crate::{List, get_current_list, config::Cfg, input::Input}; +use crate::{List, get_current_list, config::Cfg}; -pub async fn download(config: Cfg, input: Input) -> MLE<()> { +pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { let mut liststack: Vec = vec![]; - if input.all_lists { + if all_lists { let list_ids = lists_get_all_ids(config.clone())?; for id in list_ids { liststack.push(lists_get(config.clone(), id)?); @@ -33,7 +33,7 @@ pub async fn download(config: Cfg, input: Input) -> MLE<()> { let current_download = downloaded_versions.get(&mod_id); - if current_download.is_none() || input.clean { + if current_download.is_none() || clean { to_download.push(current_version); } else { let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); @@ -44,7 +44,7 @@ pub async fn download(config: Cfg, input: Input) -> MLE<()> { } } - if input.clean { clean_list_dir(¤t_list)? }; + if clean { clean_list_dir(¤t_list)? }; if !to_download.is_empty() { download_versions(current_list.clone(), config.clone(), get_raw_versions(&config.apis.modrinth, to_download).await).await?; @@ -54,7 +54,7 @@ pub async fn download(config: Cfg, input: Input) -> MLE<()> { if !to_disable.is_empty() { for ver in to_disable { - if input.delete_old { + if delete_old { println!("Deleting version {} for mod {}", ver.1, ver.0); delete_version(current_list.clone(), ver.1)?; } else { diff --git a/src/commands/io.rs b/src/commands/io.rs index a3d056f..5de8dd1 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -2,7 +2,7 @@ use std::fs::File; use std::io::prelude::*; use serde::{Serialize, Deserialize}; -use crate::{input::{Input, IoOptions}, db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mods_add, IDSelector}; +use crate::{db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mod_add, IDSelector}; #[derive(Debug, Serialize, Deserialize)] struct Export { @@ -32,22 +32,12 @@ impl ExportList { } } -pub async fn io(config: Cfg, input: Input) -> MLE<()> { - - match input.clone().io_options.unwrap() { - IoOptions::Export => { export(config, input)? }, - IoOptions::Import => { import(config, input).await? }, - } - - Ok(()) -} - -fn export(config: Cfg, input: Input) -> MLE<()> { +pub fn export(config: Cfg, list: Option) -> MLE<()> { let mut list_ids: Vec = vec![]; - if input.all_lists { + if list.is_none() { list_ids = lists_get_all_ids(config.clone())?; } else { - list_ids.push(lists_get(config.clone(), input.list.unwrap().id)?.id); + list_ids.push(lists_get(config.clone(), list.unwrap())?.id); } let mut lists: Vec = vec![]; for list_id in list_ids { @@ -64,14 +54,9 @@ fn export(config: Cfg, input: Input) -> MLE<()> { Ok(()) } -async fn import(config: Cfg, input: Input) -> MLE<()> { +pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { - let filestr: String = match input.file { - Some(args) => args, - None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), - }; - - let mut file = File::open(filestr)?; + let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; let export: Export = toml::from_str(&content)?; @@ -86,7 +71,7 @@ async fn import(config: Cfg, input: Input) -> MLE<()> { }; //TODO impl set_version and good direct download //TODO impl all at once, dafuck - mods_add(config.clone(), mod_ids, list, input.direct_download, false).await?; + mod_add(config.clone(), mod_ids, list, direct_download, false).await?; } Ok(()) } diff --git a/src/commands/list.rs b/src/commands/list.rs index 8e86973..80e801a 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,4 +1,4 @@ -use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, input::{Input, ListOptions}, cmd_update, error::MLE}; +use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, update, error::MLE}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -8,44 +8,23 @@ pub struct List { pub download_folder: String, } -pub async fn list(config: Cfg, input: Input) -> MLE<()> { - - match input.clone().list_options.unwrap() { - ListOptions::Add => { - add(config, input) - }, - ListOptions::Change => { - change(config, input) - }, - ListOptions::Remove => { - remove(config, input) - }, - ListOptions::Version => { - version(config, input).await - } - } -} - pub fn get_current_list(config: Cfg) -> MLE { let id = config_get_current_list(config.clone())?; lists_get(config, id) } -fn add(config: Cfg, input: Input) -> MLE<()> { - let id = input.list_id.unwrap(); - let mc_version = input.list_mcversion.unwrap(); - let mod_loader = input.modloader.unwrap(); - let download_folder = input.directory.unwrap(); - lists_insert(config, id, mc_version, mod_loader, download_folder) +pub fn list_add(config: Cfg, id: String, mc_version: String, modloader: Modloader, directory: String) -> MLE<()> { + lists_insert(config, id, mc_version, modloader, directory) } -fn change(config: Cfg, input: Input) -> MLE<()> { - println!("Change default list to: {}", input.clone().list.unwrap().id); - config_change_current_list(config, input.list.unwrap().id) +pub fn list_change(config: Cfg, id: String) -> MLE<()> { + //TODO check if list exists + println!("Change default list to: {}", id); + config_change_current_list(config, id) } -fn remove(config: Cfg, input: Input) -> MLE<()> { - lists_remove(config, input.list.unwrap().id) +pub fn list_remove(config: Cfg, id: String) -> MLE<()> { + lists_remove(config, id) } ///Changing the current lists version and updating it @@ -54,14 +33,12 @@ fn remove(config: Cfg, input: Input) -> MLE<()> { /// /// * `config` - The current config /// * `args` - All args, to extract the new version -async fn version(config: Cfg, input: Input) -> MLE<()> { - println!("Change version for list {} to minecraft version: {}", input.clone().list.unwrap().id, input.clone().list_mcversion.unwrap()); +pub async fn list_version(config: Cfg, id: String, mc_version: String, download: bool, delete: bool) -> MLE<()> { + println!("Change version for list {} to minecraft version: {}", id, mc_version); - lists_version(config.clone(), input.clone().list.ok_or("").unwrap().id, input.clone().list_mcversion.ok_or("").unwrap())?; - - //Linebreak readability - println!(""); + lists_version(config.clone(), &id, &mc_version)?; - println!("Check for updates for new minecraft version in list {}", input.clone().list.unwrap().id); - cmd_update(config, vec![input.list.ok_or("").unwrap()], true, input.direct_download, input.delete_old).await + println!("\nCheck for updates for new minecraft version in list {}", id); + let list = lists_get(config.clone(), id)?; + update(config, vec![list], true, download, delete).await } diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 31e50af..454e148 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,4 +1,4 @@ -use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, input::{Input, ModOptions}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; +use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum IDSelector { @@ -6,24 +6,6 @@ pub enum IDSelector { VersionID(String) } -pub async fn modification(config: Cfg, input: Input) -> MLE<()> { - match input.clone().mod_options.ok_or("").unwrap() { - ModOptions::Add => { - add(config, input).await - }, - ModOptions::Remove => { - remove(config, input) - }, - } -} - -async fn add(config: Cfg, input: Input) -> MLE<()> { - - mods_add(config, vec![input.mod_id.unwrap()], input.list.unwrap(), input.direct_download, input.set_version).await?; - - Ok(()) -} - #[derive(Debug, Clone)] pub struct ProjectInfo { pub mod_id: String, @@ -34,7 +16,7 @@ pub struct ProjectInfo { pub download_link: String, } -pub async fn mods_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { +pub async fn mod_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { println!("Add mods to {}", list.id); println!(" └Add mods:"); @@ -156,22 +138,24 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE Ok(projectinfo) } -fn remove(config: Cfg, input: Input) -> MLE<()> { - - let id = match input.clone().mod_id.unwrap() { - IDSelector::ModificationID(id) => id, - IDSelector::VersionID(..) => return Err(MLError::new(ErrorType::ArgumentError, "NO_MOD_ID")), - }; +/// Remove mod from a list +/// # Arguments +/// +/// * `config` - config struct +/// * `id` - name, slug or id of the mod +/// * `list` - List struct +pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { - let mod_id = mods_get_id(&config.data, &id)?; + let mod_id = mods_get_id(&config.data, id)?; - let version = userlist_get_current_version(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; + let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; - userlist_remove(config.clone(), input.clone().list.unwrap().id, String::from(&mod_id))?; - delete_version(input.list.unwrap(), version)?; + userlist_remove(config.clone(), &list.id, &mod_id)?; + delete_version(list, version)?; let list_ids = lists_get_all_ids(config.clone())?; + // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { let mods = userlist_get_all_ids(config.clone(), id)?; diff --git a/src/commands/update.rs b/src/commands/update.rs index 75bee39..e5751c0 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,21 +1,6 @@ -use crate::{config::Cfg, modrinth::{versions, extract_current_version, Version}, get_current_list, db::{userlist_get_all_ids, userlist_get_applicable_versions, userlist_change_versions, lists_get_all_ids, lists_get, userlist_get_current_version, userlist_get_set_version, mods_get_info}, List, input::Input, files::{delete_version, download_versions, disable_version, clean_list_dir}, error::{MLE, MLError, ErrorType}}; - -pub async fn update(config: Cfg, input: Input) -> MLE<()> { - let mut liststack: Vec = vec![]; - if input.all_lists { - let list_ids = lists_get_all_ids(config.clone())?; - for id in list_ids { - liststack.push(lists_get(config.clone(), id)?); - } - } else { - let current = get_current_list(config.clone())?; - println!("Update list {}:", current.id); - liststack.push(current) - } - cmd_update(config, liststack, input.clean, input.direct_download, input.delete_old).await -} +use crate::{config::Cfg, modrinth::{versions, extract_current_version, Version}, db::{userlist_get_all_ids, userlist_get_applicable_versions, userlist_change_versions, userlist_get_current_version, userlist_get_set_version, mods_get_info}, List, files::{delete_version, download_versions, disable_version, clean_list_dir}, error::{MLE, MLError, ErrorType}}; -pub async fn cmd_update(config: Cfg, liststack: Vec, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> { +pub async fn update(config: Cfg, liststack: Vec, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> { for current_list in liststack { let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; @@ -34,7 +19,7 @@ pub async fn cmd_update(config: Cfg, liststack: Vec, clean: bool, direct_d } //Getting current installed version for disable or delete - let disable_version = userlist_get_current_version(config.clone(), String::from(¤t_list.id), String::from(&id))?; + let disable_version = userlist_get_current_version(config.clone(), ¤t_list.id, &id)?; updatestack.push( match specific_update(config.clone(), clean, current_list.clone(), String::from(&id)).await { @@ -110,6 +95,7 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML }?; current.push(current_ver.clone()); + //TODO implement version selection if no primary let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { Ok(p) => Ok(p), Err(e) => Err(MLError::new(ErrorType::Other, e)), diff --git a/src/config.rs b/src/config.rs index ded0062..075d884 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,7 +27,7 @@ impl Cfg { let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; let mut file = File::create(devdir(configfile.to_str().unwrap()))?; println!("Created config file"); - file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?; + file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; File::open(devdir(configfile.to_str().unwrap()))? } else { return Err(err.into()); diff --git a/src/db.rs b/src/db.rs index 9428466..2c48cab 100644 --- a/src/db.rs +++ b/src/db.rs @@ -49,6 +49,9 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box MLE { + + //TODO check if "slug" is id + let data = devdir(format!("{}/data.db", data).as_str()); let connection = Connection::open(data)?; @@ -192,8 +195,7 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { } } - -pub fn userlist_remove(config: Cfg, list_id: String, mod_id: String) -> MLE<()> { +pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -242,7 +244,7 @@ pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: Stri Ok(versions) } -pub fn userlist_get_current_version(config: Cfg, list_id: String, mod_id: String) -> MLE { +pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); @@ -425,7 +427,7 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE { Ok(list) } -pub fn lists_version(config: Cfg, list_id: String, version: String) -> MLE<()> { +pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); diff --git a/src/lib.rs b/src/lib.rs index eb845d8..8d97d1a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ pub mod db; pub mod error; pub mod files; -use std::path::Path; +use std::{path::Path, fmt::Display}; pub use apis::*; pub use commands::*; @@ -19,14 +19,7 @@ pub enum Modloader { } impl Modloader { - fn to_string(&self) -> String { - match self { - Modloader::Fabric => String::from("fabric"), - Modloader::Forge => String::from("forge"), - } - } - - fn from(string: &str) -> MLE { + pub fn from(string: &str) -> MLE { match string { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), @@ -35,6 +28,15 @@ impl Modloader { } } +impl Display for Modloader { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Modloader::Fabric => write!(f, "fabric"), + Modloader::Forge => write!(f, "forge"), + } + } +} + pub fn devdir(path: &str) -> String { let p = Path::new(path); let dev = std::env::var("DEV"); diff --git a/src/main.rs b/src/main.rs index 32727c7..0dfc190 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,65 +1,237 @@ -use std::{env, process}; +use clap::{Parser, Subcommand}; +use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; -use modlist::{config::Cfg, input::{get_input, Cmd}, update, download, list, io, modification, setup}; +//TODO make default list optional + +#[derive(Parser)] +#[command(author, version, about)] +struct Cli { + #[command(subcommand)] + command: Commands, +} + +#[derive(Subcommand)] +enum Commands { + r#Mod { + #[command(subcommand)] + command: ModCommands, + }, + List { + #[command(subcommand)] + command: ListCommands + }, + Download { + /// download all lists + #[arg(short, long)] + all: bool, + + /// clean all mods before downloading them + #[arg(short, long)] + clean: bool, + + /// remove disabled versions + #[arg(short, long)] + remove: bool, + }, + Update { + /// download all lists + #[arg(short, long)] + all: bool, + + /// directly download updated mods + #[arg(short, long)] + download: bool, + + /// clean all mods before downloading them + #[arg(short, long)] + clean: bool, + + /// delete disabled versions + #[arg(short, long)] + remove: bool, + }, + Import { + #[arg(short, long)] + file: Option, + + /// directly download imported mods + #[arg(short, long)] + download: bool, + }, + Export { + /// the list you want to export + list: Option + } +} + +#[derive(Subcommand)] +enum ModCommands { + Add { + /// id of the mod/version + id: String, + + /// set id mode to version + #[arg(short, long)] + version: bool, + + /// directly download the mod + #[arg(short, long)] + download: bool, + + /// lock the version added + #[arg(/* short , */long)] + lock: bool, + + /// optional List selection, else default list will be used + #[arg(short, long)] + list: Option + }, + Remove { + /// id, name or title of the mod + id: String, + + /// optional List selection, else default list will be used + #[arg(short, long)] + list: Option + } +} + +#[derive(Subcommand)] +enum ListCommands { + Add { + /// list id + id: String, + + directory: String, + + modloader: Option, + + version: Option, + }, + Remove { + /// id, name or title of the list + id: String + }, + List, + Change { + /// id of the list to change to + id: String + }, + Version { + /// list id + id: String, + /// desired minecraft version + version: String, + + /// directly download updated mods + #[arg(long, short)] + download: bool, + + /// delete disabled versions + #[arg(short, long)] + remove: bool, + } +} #[tokio::main] async fn main() { + + let cli = Cli::parse(); + let config = Cfg::init("modlist.toml").unwrap(); - - let mut args: Vec = env::args().collect(); - args.reverse(); - args.pop(); - args.reverse(); - - if args.is_empty() { - println!("Please enter an argument"); - process::exit(1); - }; - - let input = match get_input(config.clone(), args).await { - Ok(i) => i, - Err(e) => { - println!("{}", e); - process::exit(1); - } - }; - - match input.clone().command.unwrap() { - Cmd::Mod => { - modification(config, input).await - }, - Cmd::List => { - list(config, input).await - }, - Cmd::Update => { - update(config, input).await - }, - Cmd::Download => { - download(config, input).await + println!("{:?}", config); + + //TODO setup? maybe setup on install + match cli.command { + Commands::Mod { command } => { + + match command { + #[allow(unused_variables)] + ModCommands::Add { id, version, list, download, lock } => { + let listf = match list { + Some(list) => lists_get(config.clone(), list).unwrap(), + None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + }; + + let marked_id = match version { + true => IDSelector::VersionID(id), + false => IDSelector::ModificationID(id), + }; + + mod_add(config, vec![marked_id], listf, download, lock).await + } + ModCommands::Remove { id, list } => { + //TODO add output + //TODO add success even if no file found + let listf = match list { + Some(list) => lists_get(config.clone(), list).unwrap(), + None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + }; + mod_remove(config, &id, listf) + } + } }, - Cmd::Io => { - io(config, input).await + Commands::List { command } => { + match command { + ListCommands::Add { id, directory, modloader, version } => { + let ml = match modloader { + Some(ml) => Modloader::from(&ml).unwrap(), + //TODO add default modloader to config + None => Modloader::Fabric, + }; + + let ver = match version { + Some(ver) => ver, + //TODO get latest version + //TODO impl config for specific version or latest or latest snap + None => "1.19.4".to_string(), + }; + + list_add(config, id, ver, ml, directory) + }, + ListCommands::Remove { id } => { + list_remove(config, id) + }, + ListCommands::List => { + todo!() + }, + ListCommands::Change { id } => { + list_change(config, id) + }, + ListCommands::Version { id, version, download, remove } => { + list_version(config, id, version, download, remove).await + } + } }, - Cmd::Version => { - show_version(); - Ok(()) + //TODO a add specific list + Commands::Update { all, download, clean, remove } => { + let mut liststack: Vec = vec![]; + if all { + let list_ids = lists_get_all_ids(config.clone()).unwrap(); + for id in list_ids { + liststack.push(lists_get(config.clone(), id).unwrap()); + } + } else { + let current = get_current_list(config.clone()).unwrap(); + println!("Update list {}:", current.id); + liststack.push(current) + } + update(config, liststack, clean, download, remove).await }, - Cmd::Setup => { - setup(config).await + //TODO add specific list + Commands::Download { all, clean, remove } => { + download(config, all, clean, remove).await }, - }.unwrap() -} + Commands::Import { file, download } => { + let filestr: String = match file { + Some(args) => args, + None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), + }; -fn show_version() { - match std::env::var("DEV") { - Ok(dev) => { - let devint = dev.parse::().unwrap(); - if devint >= 1 { - println!("Modlist by FxQnLr v{} (DEV)", env!("CARGO_PKG_VERSION")); - } else { - println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")); - } + import(config, filestr, download).await }, - Err(..) => println!("Modlist by FxQnLr v{}", env!("CARGO_PKG_VERSION")), - } + Commands::Export { list } => { + export(config, list) + }, + }.unwrap(); } -- cgit v1.2.3 From 217b1bfaba0011aabf85c63912b53bcb8e5288cf Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Mon, 17 Apr 2023 20:34:01 +0200 Subject: removed old input entirely --- src/input.rs | 344 ----------------------------------------------------------- src/lib.rs | 1 - 2 files changed, 345 deletions(-) delete mode 100644 src/input.rs diff --git a/src/input.rs b/src/input.rs deleted file mode 100644 index 6c62ab7..0000000 --- a/src/input.rs +++ /dev/null @@ -1,344 +0,0 @@ -use crate::{error::{MLE, MLError, ErrorType}, Modloader, config::Cfg, db::lists_get, get_current_list, List, modrinth::{get_minecraft_version, MCVersionType}, IDSelector}; - -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct Input { - pub command: Option, - pub mod_options: Option, - pub mod_id: Option, - pub set_version: bool, - pub all_lists: bool, - pub clean: bool, - pub direct_download: bool, - pub delete_old: bool, - pub list: Option, - pub list_options: Option, - pub list_id: Option, - pub list_mcversion: Option, - pub modloader: Option, - pub directory: Option, - pub io_options: Option, - pub file: Option, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum Cmd { - Mod, - List, - Update, - Download, - Io, - Version, - Setup, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ModOptions { - Add, - Remove -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ListOptions { - Add, - Remove, - Change, - Version, -} - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum IoOptions { - Export, - Import -} - -impl Input { - fn from(config: Cfg, input: Vec) -> MLE { - let input_string = input.join(" "); - let mut args: Vec<&str> = input_string.split(" -").collect(); - args[0] = args[0].split_at(1).1; - - let mut command: Option = None; - - let mut mod_options: Option = None; - let mut mod_id: Option = None; - let mut set_version = false; - let mut all_lists = false; - let mut clean = false; - let mut direct_download = true; - let mut delete_old = false; - let mut list: Option = None; - let mut list_options: Option = None; - let mut list_id: Option = None; - let mut list_mcversion: Option = None; - let mut modloader: Option = None; - let mut directory: Option = None; - let mut io_options: Option = None; - let mut file: Option = None; - - for arg in args { - let arg_split: Vec<&str> = arg.trim().split(' ').collect(); - match arg_split[0] { - "v" | "version" => { - command = Some(Cmd::Version); - }, - "d" | "download" => { - command = Some(Cmd::Download); - }, - "u" | "update" => { - command = Some(Cmd::Update); - }, - "ma" => { - command = Some(Cmd::Mod); - mod_options = Some(ModOptions::Add); - if arg_split.len() == 2 { - mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list mod slug or id")); - } - }, - //TODO impl this - "mv" => { - command = Some(Cmd::Mod); - mod_options = Some(ModOptions::Add); - if arg_split.len() == 2 { - mod_id = Some(IDSelector::VersionID(String::from(arg_split[1]))); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a version id")); - }; - }, - "mr" => { - command = Some(Cmd::Mod); - mod_options = Some(ModOptions::Remove); - if arg_split.len() == 2 { - mod_id = Some(IDSelector::ModificationID(String::from(arg_split[1]))); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a mod id")); - }; - }, - "set_version" => { - set_version = true; - }, - "all_lists" => { - all_lists = true; - }, - "clean" => { - clean = true; - }, - "no_download" => { - direct_download = false; - }, - "delete_old" => { - delete_old = true; - }, - "l" => { - if arg_split.len() == 2 { - list = Some(lists_get(config.clone(), String::from(arg_split[1]))?); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a list via it's id")); - } - } - "la" => { - command = Some(Cmd::List); - list_options = Some(ListOptions::Add); - if arg_split.len() == 2 { - list_id = Some(String::from(arg_split[1])); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please give the new list an id")); - } - }, - "lr" => { - command = Some(Cmd::List); - list_options = Some(ListOptions::Remove); - }, - "lc" => { - command = Some(Cmd::List); - list_options = Some(ListOptions::Change); - }, - "lv" => { - command = Some(Cmd::List); - list_options = Some(ListOptions::Version); - if arg_split.len() == 2 { - list_mcversion = Some(String::from(arg_split[1])); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version")); - } - }, - "mcv" => { - if arg_split.len() == 2 { - list_mcversion = Some(String::from(arg_split[1])); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a minecraft version")); - } - }, - "ml" => { - if arg_split.len() == 2 { - modloader = Some(Modloader::from(arg_split[1])?); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a modloader")); - } - }, - "dir" => { - if arg_split.len() == 2 { - directory = Some(String::from(arg_split[1])); - } else { - return Err(MLError::new(ErrorType::ArgumentError, "Please specify a directory")); - } - }, - "export" => { - command = Some(Cmd::Io); - io_options = Some(IoOptions::Export); - }, - "import" => { - command = Some(Cmd::Io); - io_options = Some(IoOptions::Import); - }, - "f" => { - file = Some(String::from(arg_split[1])); - }, - "setup" => { - command = Some(Cmd::Setup); - } - _ => return Err(MLError::new(ErrorType::ArgumentError, format!("Unknown Argument ({})", arg_split[0]).as_str())), - } - } - - Ok(Self { - command, - mod_options, - mod_id, - set_version, - all_lists, - clean, - direct_download, - delete_old, - list, - list_options, - list_id, - list_mcversion, - modloader, - directory, - io_options, - file - }) - } -} - -pub async fn get_input(config: Cfg, args: Vec) -> MLE { - let input = Input::from(config.clone(), args)?; - - if input.command.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No command specified")); }; - - match input.clone().command.unwrap() { - Cmd::Mod => check_mod(input, config), - Cmd::List => check_list(input, config).await, - _ => Ok(input), - } -} - -fn check_mod(mut input: Input, config: Cfg) -> MLE { - if input.mod_options.is_none() { - return Err(MLError::new(ErrorType::ArgumentError, "No mod option")); - }; - match input.clone().mod_options.unwrap() { - ModOptions::Add => { - if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "No mod id/slug or version id")); }; - if input.list_id.is_none() { input.list = Some(get_current_list(config)?); }; - Ok(input) - }, - ModOptions::Remove => { - if input.mod_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "MODS_NO_MODID")); }; - if input.list_id.is_none() { input.list = Some(get_current_list(config)?); }; - Ok(input) - }, - } -} - -async fn check_list(mut input: Input, config: Cfg) -> MLE { - if input.list_options.is_none() { - return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_ARGUMENT")); - }; - match input.clone().list_options.unwrap() { - ListOptions::Add => { - if input.list_id.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no list id specified")); }; - if input.list_mcversion.is_none() { - println!("No Minecraft Version specified, defaulting to latest release"); - input.list_mcversion = Some(get_minecraft_version(&config.apis.modrinth, MCVersionType::Release).await); - }; - if input.directory.is_none() { - let id = input.clone().list_id.unwrap(); - println!("No download directory specified, defaulting to ./downloads/{}", id); - input.directory = Some(format!("./downloads/{}", id)) - }; - if input.modloader.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "no modloader specified")); }; - Ok(input) - }, - ListOptions::Remove => { - if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); }; - Ok(input) - }, - ListOptions::Change => { - if input.list.is_none() { return Err(MLError::new(ErrorType::ArgumentError, "NO_LIST_SPECIFIED")); }; - Ok(input) - }, - ListOptions::Version => { - if input.list.is_none() { - println!("No list specified, using default"); - input.list = Some(get_current_list(config)?); - }; - Ok(input) - } - } -} - -#[test] -fn input_from() { - let config = Cfg::init("modlist.toml").unwrap(); - assert_eq!( - Input::from(config, vec![String::from("-la test -lv 1.19.3")]).unwrap(), - Input { - command: Some(Cmd::List), - mod_options: None, - mod_id: None, - set_version: false, - all_lists: false, - clean: false, - direct_download: false, - delete_old: false, - list: None, - list_options: Some(ListOptions::Add), - list_id: Some(String::from("test")), - list_mcversion: Some(String::from("1.19.3")), - modloader: None, - directory: None, - io_options: None, - file: None, - } - ); - -} - -#[tokio::test] -async fn get_input_test() { - let config = Cfg::init("modlist.toml").unwrap(); - assert_eq!( - get_input(config.clone(), vec![String::from("-ma test")]).await.unwrap(), - Input { - command: Some(Cmd::Mod), - mod_options: Some(ModOptions::Add), - mod_id: Some(IDSelector::ModificationID(String::from("test"))), - set_version: false, - all_lists: false, - clean: false, - direct_download: false, - delete_old: false, - list: Some(lists_get(config.clone(), String::from("one")).unwrap()), - list_options: None, - list_id: None, - list_mcversion: None, - modloader: None, - directory: None, - io_options: None, - file: None - } - ) -} diff --git a/src/lib.rs b/src/lib.rs index 8d97d1a..9db907d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ pub mod apis; pub mod config; pub mod commands; -pub mod input; pub mod db; pub mod error; pub mod files; -- cgit v1.2.3 From 3047c83714b28432fb8b4b60261f761526eb1f2e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 18 Apr 2023 17:26:50 +0200 Subject: add shell completion --- Cargo.lock | 73 ++++++++++++++++++++++++++++++++++++++----------------------- Cargo.toml | 3 ++- src/main.rs | 10 +++++++-- 3 files changed, 56 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5638eb6..f99cd87 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -39,42 +39,51 @@ dependencies = [ [[package]] name = "anstream" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" dependencies = [ "anstyle", "anstyle-parse", + "anstyle-query", "anstyle-wincon", - "concolor-override", - "concolor-query", + "colorchoice", "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "0.3.5" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] name = "anstyle-parse" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ "utf8parse", ] +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "anstyle-wincon" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" dependencies = [ "anstyle", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -157,9 +166,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.1" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" +checksum = "9b802d85aaf3a1cdb02b224ba472ebdea62014fccfcb269b95a4d76443b5ee5a" dependencies = [ "clap_builder", "clap_derive", @@ -168,9 +177,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.1" +version = "4.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +checksum = "14a1a858f532119338887a4b8e1af9c60de8249cd7bafd68036a489e261e37b6" dependencies = [ "anstream", "anstyle", @@ -179,6 +188,15 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01c22dcfb410883764b29953103d9ef7bb8fe21b3fa1158bc99986c2067294bd" +dependencies = [ + "clap", +] + [[package]] name = "clap_derive" version = "4.2.0" @@ -208,19 +226,10 @@ dependencies = [ ] [[package]] -name = "concolor-override" +name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" - -[[package]] -name = "concolor-query" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" -dependencies = [ - "windows-sys 0.45.0", -] +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "core-foundation" @@ -789,10 +798,11 @@ dependencies = [ [[package]] name = "modlist" -version = "0.11.1" +version = "0.12.0" dependencies = [ "chrono", "clap", + "clap_complete", "dirs", "error-chain", "futures-util", @@ -1660,6 +1670,15 @@ dependencies = [ "windows-targets 0.42.2", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + [[package]] name = "windows-targets" version = "0.42.2" diff --git a/Cargo.toml b/Cargo.toml index 1f5c1cf..51652f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "modlist" -version = "0.11.1" +version = "0.12.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -17,3 +17,4 @@ toml = "0.7.2" error-chain = "0.12.4" dirs = "5.0.0" clap = { version = "4.2.1", features = ["derive"] } +clap_complete = "4.2.0" diff --git a/src/main.rs b/src/main.rs index 0dfc190..a9071f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,7 @@ -use clap::{Parser, Subcommand}; +use clap::{Parser, Subcommand, CommandFactory}; use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; //TODO make default list optional - #[derive(Parser)] #[command(author, version, about)] struct Cli { @@ -61,6 +60,9 @@ enum Commands { Export { /// the list you want to export list: Option + }, + Completions { + shell: clap_complete::Shell, } } @@ -233,5 +235,9 @@ async fn main() { Commands::Export { list } => { export(config, list) }, + Commands::Completions { shell } => { + clap_complete::generate(shell, &mut Cli::command(), "modlist", &mut std::io::stdout()); + Ok(()) + } }.unwrap(); } -- cgit v1.2.3 From fde646a876cc43857a278ef09250263a21d547ee Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Tue, 18 Apr 2023 17:35:09 +0200 Subject: remove generate again --- src/main.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index a9071f1..e845be1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use clap::{Parser, Subcommand, CommandFactory}; +use clap::{Parser, Subcommand}; use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; //TODO make default list optional @@ -61,9 +61,6 @@ enum Commands { /// the list you want to export list: Option }, - Completions { - shell: clap_complete::Shell, - } } #[derive(Subcommand)] @@ -235,9 +232,5 @@ async fn main() { Commands::Export { list } => { export(config, list) }, - Commands::Completions { shell } => { - clap_complete::generate(shell, &mut Cli::command(), "modlist", &mut std::io::stdout()); - Ok(()) - } }.unwrap(); } -- cgit v1.2.3 From 8050cfcd70a16273cc2814fe29c8ee08320d85d3 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Thu, 20 Apr 2023 15:13:58 +0200 Subject: cargo fmt --- src/apis/modrinth.rs | 56 +++--- src/commands/download.rs | 38 +++- src/commands/io.rs | 51 ++++-- src/commands/list.rs | 38 +++- src/commands/mod.rs | 16 +- src/commands/modification.rs | 181 ++++++++++++++---- src/commands/setup.rs | 12 +- src/commands/update.rs | 116 +++++++++--- src/config.rs | 16 +- src/db.rs | 423 +++++++++++++++++++++++++++++-------------- src/error.rs | 37 +++- src/files.rs | 59 ++++-- src/lib.rs | 10 +- src/main.rs | 115 +++++++----- 14 files changed, 823 insertions(+), 345 deletions(-) diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index bb5ee19..9afe7f3 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -2,7 +2,10 @@ use chrono::{DateTime, FixedOffset}; use reqwest::Client; use serde::Deserialize; -use crate::{Modloader, List, error::{MLE, MLError, ErrorType}}; +use crate::{ + error::{ErrorType, MLError, MLE}, + List, Modloader, +}; #[derive(Debug, Deserialize, Clone)] pub struct Project { @@ -47,7 +50,7 @@ pub struct ModeratorMessage { pub enum Side { required, optional, - unsupported + unsupported, } #[allow(non_camel_case_types)] @@ -55,7 +58,7 @@ pub enum Side { pub enum Type { r#mod, modpack, - recourcepack + recourcepack, } #[allow(non_camel_case_types)] @@ -63,9 +66,11 @@ pub enum Type { pub enum Status { approved, rejected, - draft, unlisted, archived, + draft, + unlisted, + archived, processing, - unknown + unknown, } #[derive(Debug, Clone, Deserialize)] @@ -90,7 +95,7 @@ pub struct Version { pub enum VersionType { release, beta, - alpha + alpha, } #[derive(Debug, Clone, Deserialize)] @@ -110,22 +115,19 @@ pub struct Hash { async fn get(api: &str, path: String) -> Result>, Box> { let url = format!(r#"{}{}"#, api, path); - + let client = Client::builder() - .user_agent(format!("fxqnlr/modlistcli/{} (fxqnlr@gmail.com)", env!("CARGO_PKG_VERSION"))) + .user_agent(format!( + "fxqnlr/modlistcli/{} (fxqnlr@gmail.com)", + env!("CARGO_PKG_VERSION") + )) .build()?; - let res = client.get(url) - .send() - .await?; - + let res = client.get(url).send().await?; + let mut data: Option> = None; if res.status() == 200 { - data = Some(res - .bytes() - .await? - .to_vec() - ); + data = Some(res.bytes().await?.to_vec()); } Ok(data) @@ -143,7 +145,7 @@ pub async fn projects(api: &str, ids: Vec) -> Vec { let url = format!(r#"projects?ids=["{}"]"#, all); let data = get(api, url).await.unwrap().unwrap(); - + serde_json::from_slice(&data).unwrap() } @@ -154,7 +156,10 @@ pub async fn versions(api: &str, id: String, list: List) -> Vec { Modloader::Fabric => String::from("fabric"), }; - let url = format!(r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, id, loaderstr, list.mc_version); + let url = format!( + r#"project/{}/version?loaders=["{}"]&game_versions=["{}"]"#, + id, loaderstr, list.mc_version + ); let data = get(api, url).await.unwrap(); @@ -185,7 +190,7 @@ pub fn extract_current_version(versions: Vec) -> MLE { times.sort_by_key(|t| t.1); times.reverse(); Ok(times[0].0.to_string()) - }, + } _ => panic!("available_versions should never be negative"), } } @@ -205,16 +210,19 @@ pub struct MCVersion { } pub async fn get_minecraft_version(api: &str, version: MCVersionType) -> String { - let data = get(api, String::from("tag/game_version")).await.unwrap().unwrap(); + let data = get(api, String::from("tag/game_version")) + .await + .unwrap() + .unwrap(); let mc_versions: Vec = serde_json::from_slice(&data).unwrap(); let ver = match version { MCVersionType::Release => { let mut i = 0; - while !mc_versions[i].major { + while !mc_versions[i].major { i += 1; - }; + } &mc_versions[i] - }, + } MCVersionType::Latest => &mc_versions[0], MCVersionType::Specific => { println!("Not inplemented"); diff --git a/src/commands/download.rs b/src/commands/download.rs index 4baecee..9434591 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,8 +1,14 @@ -use crate::{files::{get_downloaded_versions, download_versions, delete_version, disable_version, clean_list_dir}, db::{userlist_get_all_current_versions_with_mods, lists_get_all_ids, lists_get}, modrinth::get_raw_versions, error::{MLE, ErrorType, MLError}}; -use crate::{List, get_current_list, config::Cfg}; +use crate::{config::Cfg, get_current_list, List}; +use crate::{ + db::{lists_get, lists_get_all_ids, userlist_get_all_current_versions_with_mods}, + error::{ErrorType, MLError, MLE}, + files::{ + clean_list_dir, delete_version, disable_version, download_versions, get_downloaded_versions, + }, + modrinth::get_raw_versions, +}; pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: bool) -> MLE<()> { - let mut liststack: Vec = vec![]; if all_lists { let list_ids = lists_get_all_ids(config.clone())?; @@ -18,7 +24,10 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo for current_list in liststack { let downloaded_versions = get_downloaded_versions(current_list.clone())?; println!("To download: {:#?}", downloaded_versions); - let current_version_ids = match userlist_get_all_current_versions_with_mods(config.clone(), String::from(¤t_list.id)) { + let current_version_ids = match userlist_get_all_current_versions_with_mods( + config.clone(), + String::from(¤t_list.id), + ) { Ok(i) => Ok(i), Err(e) => Err(MLError::new(ErrorType::DBError, e.to_string().as_str())), }?; @@ -36,28 +45,37 @@ pub async fn download(config: Cfg, all_lists: bool, clean: bool, delete_old: boo if current_download.is_none() || clean { to_download.push(current_version); } else { - let downloaded_version = current_download.ok_or("SOMETHING_HAS_REALLY_GONE_WRONG").unwrap(); + let downloaded_version = current_download + .ok_or("SOMETHING_HAS_REALLY_GONE_WRONG") + .unwrap(); if ¤t_version != downloaded_version { to_disable.push((mod_id.clone(), String::from(downloaded_version))); to_download.push(current_version); } } } - - if clean { clean_list_dir(¤t_list)? }; + + if clean { + clean_list_dir(¤t_list)? + }; if !to_download.is_empty() { - download_versions(current_list.clone(), config.clone(), get_raw_versions(&config.apis.modrinth, to_download).await).await?; + download_versions( + current_list.clone(), + config.clone(), + get_raw_versions(&config.apis.modrinth, to_download).await, + ) + .await?; } else { println!("There are no new versions to download"); } - + if !to_disable.is_empty() { for ver in to_disable { if delete_old { println!("Deleting version {} for mod {}", ver.1, ver.0); delete_version(current_list.clone(), ver.1)?; - } else { + } else { disable_version(config.clone(), current_list.clone(), ver.1, ver.0)?; }; } diff --git a/src/commands/io.rs b/src/commands/io.rs index 5de8dd1..7f03eec 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -1,12 +1,18 @@ +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::prelude::*; -use serde::{Serialize, Deserialize}; -use crate::{db::{lists_get, userlist_get_all_ids, lists_get_all_ids, lists_insert}, config::Cfg, Modloader, List, devdir, error::MLE, mod_add, IDSelector}; +use crate::{ + config::Cfg, + db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids}, + devdir, + error::MLE, + mod_add, IDSelector, List, Modloader, +}; #[derive(Debug, Serialize, Deserialize)] struct Export { - lists: Vec + lists: Vec, } #[derive(Debug, Serialize, Deserialize)] @@ -20,15 +26,22 @@ struct ExportList { impl ExportList { pub fn from(config: Cfg, list_id: String, download: bool) -> MLE { - let list = lists_get(config.clone(), String::from(&list_id))?; let mut dl_folder = None; - if download{ dl_folder = Some(list.download_folder) }; + if download { + dl_folder = Some(list.download_folder) + }; let mods = userlist_get_all_ids(config, list_id)?.join("|"); - Ok(Self { id: list.id, mods, launcher: list.modloader.to_string(), mc_version: list.mc_version, download_folder: dl_folder }) + Ok(Self { + id: list.id, + mods, + launcher: list.modloader.to_string(), + mc_version: list.mc_version, + download_folder: dl_folder, + }) } } @@ -43,32 +56,44 @@ pub fn export(config: Cfg, list: Option) -> MLE<()> { for list_id in list_ids { lists.push(ExportList::from(config.clone(), list_id, true)?); } - - let toml = toml::to_string( &Export { lists } )?; + + let toml = toml::to_string(&Export { lists })?; let filestr = dirs::home_dir().unwrap().join("mlexport.toml"); - let mut file = File::create(devdir(filestr.into_os_string().into_string().unwrap().as_str()))?; + let mut file = File::create(devdir( + filestr.into_os_string().into_string().unwrap().as_str(), + ))?; file.write_all(toml.as_bytes())?; Ok(()) } pub async fn import(config: Cfg, file_str: String, direct_download: bool) -> MLE<()> { - let mut file = File::open(file_str)?; let mut content = String::new(); file.read_to_string(&mut content)?; let export: Export = toml::from_str(&content)?; for exportlist in export.lists { - let list = List { id: exportlist.id, mc_version: exportlist.mc_version, modloader: Modloader::from(&exportlist.launcher)?, download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap() }; - lists_insert(config.clone(), list.id.clone(), list.mc_version.clone(), list.modloader.clone(), String::from(&list.download_folder))?; + let list = List { + id: exportlist.id, + mc_version: exportlist.mc_version, + modloader: Modloader::from(&exportlist.launcher)?, + download_folder: exportlist.download_folder.ok_or("NO_DL").unwrap(), + }; + lists_insert( + config.clone(), + list.id.clone(), + list.mc_version.clone(), + list.modloader.clone(), + String::from(&list.download_folder), + )?; let mods: Vec<&str> = exportlist.mods.split('|').collect(); let mut mod_ids = vec![]; for mod_id in mods { mod_ids.push(IDSelector::ModificationID(String::from(mod_id))); - }; + } //TODO impl set_version and good direct download //TODO impl all at once, dafuck mod_add(config.clone(), mod_ids, list, direct_download, false).await?; diff --git a/src/commands/list.rs b/src/commands/list.rs index 80e801a..13176f4 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,4 +1,12 @@ -use crate::{db::{lists_insert, lists_remove, config_change_current_list, config_get_current_list, lists_get, lists_version}, Modloader, config::Cfg, update, error::MLE}; +use crate::{ + config::Cfg, + db::{ + config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove, + lists_version, + }, + error::MLE, + update, Modloader, +}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct List { @@ -13,7 +21,13 @@ pub fn get_current_list(config: Cfg) -> MLE { lists_get(config, id) } -pub fn list_add(config: Cfg, id: String, mc_version: String, modloader: Modloader, directory: String) -> MLE<()> { +pub fn list_add( + config: Cfg, + id: String, + mc_version: String, + modloader: Modloader, + directory: String, +) -> MLE<()> { lists_insert(config, id, mc_version, modloader, directory) } @@ -30,15 +44,27 @@ pub fn list_remove(config: Cfg, id: String) -> MLE<()> { ///Changing the current lists version and updating it /// /// #Arguments -/// +/// /// * `config` - The current config /// * `args` - All args, to extract the new version -pub async fn list_version(config: Cfg, id: String, mc_version: String, download: bool, delete: bool) -> MLE<()> { - println!("Change version for list {} to minecraft version: {}", id, mc_version); +pub async fn list_version( + config: Cfg, + id: String, + mc_version: String, + download: bool, + delete: bool, +) -> MLE<()> { + println!( + "Change version for list {} to minecraft version: {}", + id, mc_version + ); lists_version(config.clone(), &id, &mc_version)?; - println!("\nCheck for updates for new minecraft version in list {}", id); + println!( + "\nCheck for updates for new minecraft version in list {}", + id + ); let list = lists_get(config.clone(), id)?; update(config, vec![list], true, download, delete).await } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 0d5bd00..1c7c012 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,13 +1,13 @@ -pub mod modification; -pub mod list; -pub mod update; -pub mod setup; pub mod download; pub mod io; +pub mod list; +pub mod modification; +pub mod setup; +pub mod update; -pub use modification::*; -pub use list::*; -pub use update::*; -pub use setup::*; pub use download::*; pub use io::*; +pub use list::*; +pub use modification::*; +pub use setup::*; +pub use update::*; diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 454e148..ffc4e10 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,9 +1,19 @@ -use crate::{modrinth::{versions, extract_current_version, Version, projects, get_raw_versions, project}, config::Cfg, db::{mods_insert, userlist_remove, mods_get_id, userlist_insert, userlist_get_all_ids, userlist_get_current_version, lists_get_all_ids, mods_remove}, files::{delete_version, download_versions}, List, error::{MLE, ErrorType, MLError}}; +use crate::{ + config::Cfg, + db::{ + lists_get_all_ids, mods_get_id, mods_insert, mods_remove, userlist_get_all_ids, + userlist_get_current_version, userlist_insert, userlist_remove, + }, + error::{ErrorType, MLError, MLE}, + files::{delete_version, download_versions}, + modrinth::{extract_current_version, get_raw_versions, project, projects, versions, Version}, + List, +}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum IDSelector { ModificationID(String), - VersionID(String) + VersionID(String), } #[derive(Debug, Clone)] @@ -16,10 +26,16 @@ pub struct ProjectInfo { pub download_link: String, } -pub async fn mod_add(config: Cfg, ids: Vec, list: List, direct_download: bool, set_version: bool) -> MLE<()> { +pub async fn mod_add( + config: Cfg, + ids: Vec, + list: List, + direct_download: bool, + set_version: bool, +) -> MLE<()> { println!("Add mods to {}", list.id); println!(" └Add mods:"); - + let mut mod_ids: Vec = Vec::new(); let mut ver_ids: Vec = Vec::new(); @@ -32,11 +48,17 @@ pub async fn mod_add(config: Cfg, ids: Vec, list: List, direct_downl } let mut projectinfo: Vec = Vec::new(); - if !mod_ids.is_empty() { projectinfo.append(&mut get_mod_infos(config.clone(), mod_ids, list.clone()).await?) }; - if !ver_ids.is_empty() { projectinfo.append(&mut get_ver_info(config.clone(), ver_ids).await?) }; + if !mod_ids.is_empty() { + projectinfo.append(&mut get_mod_infos(config.clone(), mod_ids, list.clone()).await?) + }; + if !ver_ids.is_empty() { + projectinfo.append(&mut get_ver_info(config.clone(), ver_ids).await?) + }; + + if projectinfo.is_empty() { + return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")); + }; - if projectinfo.is_empty() { return Err(MLError::new(ErrorType::ArgumentError, "NO_IDS?")) }; - let mut downloadstack: Vec = Vec::new(); //Adding each mod to the lists and downloadstack @@ -45,29 +67,59 @@ pub async fn mod_add(config: Cfg, ids: Vec, list: List, direct_downl } else { println!(" └Insert mods in list {} and save infos", list.id); } - + for project in projectinfo { - let current_version_id = if project.current_version.is_none() { String::from("NONE") } else { project.current_version.clone().unwrap().id }; - match userlist_insert(config.clone(), &list.id, &project.mod_id, ¤t_version_id, project.clone().applicable_versions, &project.download_link, set_version) { + let current_version_id = if project.current_version.is_none() { + String::from("NONE") + } else { + project.current_version.clone().unwrap().id + }; + match userlist_insert( + config.clone(), + &list.id, + &project.mod_id, + ¤t_version_id, + project.clone().applicable_versions, + &project.download_link, + set_version, + ) { Err(e) => { let expected_err = format!("SQL: UNIQUE constraint failed: {}.mod_id", list.id); - if e.to_string() == expected_err { Err(MLError::new(ErrorType::ModError, "MOD_ALREADY_ON_SELECTED_LIST")) } else { Err(e) } - }, - Ok(..) => { Ok(..) }, + if e.to_string() == expected_err { + Err(MLError::new( + ErrorType::ModError, + "MOD_ALREADY_ON_SELECTED_LIST", + )) + } else { + Err(e) + } + } + Ok(..) => Ok(..), }?; - - match mods_insert(config.clone(), &project.mod_id, &project.slug, &project.title) { + + match mods_insert( + config.clone(), + &project.mod_id, + &project.slug, + &project.title, + ) { Err(e) => { - if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { Ok(..) } else { Err(e) } - }, + if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { + Ok(..) + } else { + Err(e) + } + } Ok(..) => Ok(..), }?; - if project.current_version.is_some() { downloadstack.push(project.current_version.unwrap()) }; + if project.current_version.is_some() { + downloadstack.push(project.current_version.unwrap()) + }; } //Download all the added mods - if direct_download { + if direct_download { download_versions(list.clone(), config.clone(), downloadstack).await?; }; @@ -86,7 +138,12 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec, list: List) -> MLE = Vec::new(); let current_version: Option; @@ -95,36 +152,63 @@ async fn get_mod_infos(config: Cfg, mod_ids: Vec, list: List) -> MLE) -> MLE> { let mut projectinfo: Vec = Vec::new(); - + //Get required information from ver_ids let mut v_versions = get_raw_versions(&config.apis.modrinth, ver_ids).await; let mut v_mod_ids: Vec = Vec::new(); for ver in v_versions.clone() { v_mod_ids.push(ver.project_id); - }; + } let mut v_projects = projects(&config.apis.modrinth, v_mod_ids).await; v_versions.sort_by(|a, b| a.project_id.cmp(&b.project_id)); v_projects.sort_by(|a, b| a.id.cmp(&b.id)); @@ -132,9 +216,22 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE for (i, project) in v_projects.into_iter().enumerate() { let version = &v_versions[i]; println!("\t└{}({})", project.title, version.id); - let file = version.clone().files.into_iter().find(|f| f.primary).unwrap().url; - projectinfo.push(ProjectInfo { mod_id: project.id, slug: project.slug, title: project.title, current_version: Some(version.clone()), applicable_versions: vec![String::from(&version.id)], download_link: file }) - }; + let file = version + .clone() + .files + .into_iter() + .find(|f| f.primary) + .unwrap() + .url; + projectinfo.push(ProjectInfo { + mod_id: project.id, + slug: project.slug, + title: project.title, + current_version: Some(version.clone()), + applicable_versions: vec![String::from(&version.id)], + download_link: file, + }) + } Ok(projectinfo) } @@ -145,24 +242,28 @@ async fn get_ver_info(config: Cfg, ver_ids: Vec) -> MLE /// * `id` - name, slug or id of the mod /// * `list` - List struct pub fn mod_remove(config: Cfg, id: &str, list: List) -> MLE<()> { - let mod_id = mods_get_id(&config.data, id)?; - + let version = userlist_get_current_version(config.clone(), &list.id, &mod_id)?; userlist_remove(config.clone(), &list.id, &mod_id)?; delete_version(list, version)?; - + let list_ids = lists_get_all_ids(config.clone())?; - + // Remove mod from main list if not used elsewhere let mut mod_used = false; for id in list_ids { let mods = userlist_get_all_ids(config.clone(), id)?; - if mods.contains(&mod_id) { mod_used = true; break; }; - }; + if mods.contains(&mod_id) { + mod_used = true; + break; + }; + } - if !mod_used { mods_remove(config, mod_id)?; }; + if !mod_used { + mods_remove(config, mod_id)?; + }; Ok(()) } diff --git a/src/commands/setup.rs b/src/commands/setup.rs index 0161bd7..40e8c0a 100644 --- a/src/commands/setup.rs +++ b/src/commands/setup.rs @@ -1,14 +1,14 @@ use std::{fs::File, path::Path}; -use crate::{config::Cfg, db::db_setup, error::MLE, devdir}; +use crate::{config::Cfg, db::db_setup, devdir, error::MLE}; pub async fn setup(config: Cfg) -> MLE<()> { let db_file = devdir(format!("{}/data.db", config.data).as_str()); - + if !Path::new(&db_file).exists() { create(config, db_file)?; } - + /* match s_config_get_version(config.clone()) { Ok(ver) => { @@ -21,12 +21,11 @@ pub async fn setup(config: Cfg) -> MLE<()> { Err(..) => to_02(config).await? }; */ - + Ok(()) } fn create(config: Cfg, db_file: String) -> MLE<()> { - println!("Create database"); File::create(db_file)?; @@ -44,7 +43,7 @@ fn create(config: Cfg, db_file: String) -> MLE<()> { // let full_list = lists_get(config.clone(), String::from(&list))?; // // let versions = userlist_get_all_current_version_ids(config.clone(), full_list.clone().id)?; -// +// // let raw_versions = get_raw_versions(String::from(&config.apis.modrinth), versions).await; // // for ver in raw_versions { @@ -69,4 +68,3 @@ fn create(config: Cfg, db_file: String) -> MLE<()> { // } // s_config_update_version(config, String::from("0.4")) //} - diff --git a/src/commands/update.rs b/src/commands/update.rs index e5751c0..3d9578b 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,14 +1,30 @@ -use crate::{config::Cfg, modrinth::{versions, extract_current_version, Version}, db::{userlist_get_all_ids, userlist_get_applicable_versions, userlist_change_versions, userlist_get_current_version, userlist_get_set_version, mods_get_info}, List, files::{delete_version, download_versions, disable_version, clean_list_dir}, error::{MLE, MLError, ErrorType}}; - -pub async fn update(config: Cfg, liststack: Vec, clean: bool, direct_download: bool, delete_old: bool) -> MLE<()> { +use crate::{ + config::Cfg, + db::{ + mods_get_info, userlist_change_versions, userlist_get_all_ids, + userlist_get_applicable_versions, userlist_get_current_version, userlist_get_set_version, + }, + error::{ErrorType, MLError, MLE}, + files::{clean_list_dir, delete_version, disable_version, download_versions}, + modrinth::{extract_current_version, versions, Version}, + List, +}; + +pub async fn update( + config: Cfg, + liststack: Vec, + clean: bool, + direct_download: bool, + delete_old: bool, +) -> MLE<()> { for current_list in liststack { let mods = userlist_get_all_ids(config.clone(), current_list.clone().id)?; - + let mut current_versions: Vec<(String, String)> = vec![]; - + println!(" └Update mods:"); let mut updatestack: Vec = vec![]; - + for id in mods { let info = mods_get_info(config.clone(), &id)?; println!("\t└{}", info.title); @@ -19,27 +35,39 @@ pub async fn update(config: Cfg, liststack: Vec, clean: bool, direct_downl } //Getting current installed version for disable or delete - let disable_version = userlist_get_current_version(config.clone(), ¤t_list.id, &id)?; + let disable_version = + userlist_get_current_version(config.clone(), ¤t_list.id, &id)?; updatestack.push( - match specific_update(config.clone(), clean, current_list.clone(), String::from(&id)).await { + match specific_update( + config.clone(), + clean, + current_list.clone(), + String::from(&id), + ) + .await + { Ok(ver) => { current_versions.push((disable_version, id)); ver - }, + } Err(e) => { if e.to_string() == "Mod: NO_UPDATE_AVAILABLE" { - println!("\t └No new version found for the specified minecraft version"); + println!( + "\t └No new version found for the specified minecraft version" + ); } else { return Err(e); }; continue; } - } + }, ) - }; + } - if clean { clean_list_dir(¤t_list)?; }; + if clean { + clean_list_dir(¤t_list)?; + }; if direct_download && !updatestack.is_empty() { download_versions(current_list.clone(), config.clone(), updatestack).await?; @@ -50,7 +78,7 @@ pub async fn update(config: Cfg, liststack: Vec, clean: bool, direct_downl if delete_old { println!("\t └Delete version {}", ver.0); delete_version(current_list.clone(), ver.0)?; - } else if ver.0 != "NONE" { + } else if ver.0 != "NONE" { println!("\t └Disable version {}", ver.0); disable_version(config.clone(), current_list.clone(), ver.0, ver.1)?; }; @@ -63,10 +91,11 @@ pub async fn update(config: Cfg, liststack: Vec, clean: bool, direct_downl } async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> MLE { - let applicable_versions = versions(&config.apis.modrinth, String::from(&id), list.clone()).await; - + let applicable_versions = + versions(&config.apis.modrinth, String::from(&id), list.clone()).await; + let mut versions: Vec = vec![]; - + if !applicable_versions.is_empty() { for ver in &applicable_versions { versions.push(String::from(&ver.id)); @@ -77,8 +106,14 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML let mut current: Vec = vec![]; //TODO Split clean and no match - if clean || (versions.join("|") != userlist_get_applicable_versions(config.clone(), String::from(&list.id), String::from(&id))?) { - + if clean + || (versions.join("|") + != userlist_get_applicable_versions( + config.clone(), + String::from(&list.id), + String::from(&id), + )?) + { let current_str = extract_current_version(applicable_versions.clone())?; if clean { @@ -89,35 +124,54 @@ async fn specific_update(config: Cfg, clean: bool, list: List, id: String) -> ML }; //get new versions - let current_ver = match applicable_versions.into_iter().find(|ver| ver.id == current_str).ok_or("!no current version in applicable_versions") { + let current_ver = match applicable_versions + .into_iter() + .find(|ver| ver.id == current_str) + .ok_or("!no current version in applicable_versions") + { Ok(v) => Ok(v), Err(e) => Err(MLError::new(ErrorType::Other, e)), }?; current.push(current_ver.clone()); //TODO implement version selection if no primary - let link = match current_ver.files.into_iter().find(|f| f.primary).ok_or("!no primary in links") { + let link = match current_ver + .files + .into_iter() + .find(|f| f.primary) + .ok_or("!no primary in links") + { Ok(p) => Ok(p), Err(e) => Err(MLError::new(ErrorType::Other, e)), - }?.url; + }? + .url; userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id)?; } - if current.is_empty() { return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")) }; - + if current.is_empty() { + return Err(MLError::new(ErrorType::ModError, "NO_UPDATE_AVAILABLE")); + }; + //println!(" └✔️"); Ok(current[0].clone()) } #[tokio::test] async fn download_updates_test() { + use crate::{ + modrinth::{Hash, Version, VersionFile, VersionType}, + List, Modloader, + }; - use crate::{modrinth::{Version, VersionFile, Hash, VersionType}, Modloader, List}; - let config = Cfg::init("modlist.toml").unwrap(); - let current_list = List { id: String::from("..."), mc_version: String::from("..."), modloader: Modloader::Fabric, download_folder: String::from("./dev/tests/dl") }; - - let versions = vec![Version { + let current_list = List { + id: String::from("..."), + mc_version: String::from("..."), + modloader: Modloader::Fabric, + download_folder: String::from("./dev/tests/dl"), + }; + + let versions = vec![Version { id: "dEqtGnT9".to_string(), project_id: "kYuIpRLv".to_string(), author_id: "Qnt13hO8".to_string(), @@ -147,5 +201,7 @@ async fn download_updates_test() { "fabric".to_string() ] }]; - assert!(download_versions(current_list, config, versions).await.is_ok()) + assert!(download_versions(current_list, config, versions) + .await + .is_ok()) } diff --git a/src/config.rs b/src/config.rs index 075d884..1b54d5f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,8 +1,11 @@ -use std::{fs::File, io::{Read, Write}}; +use std::{ + fs::File, + io::{Read, Write}, +}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; -use crate::{error::MLE, devdir}; +use crate::{devdir, error::MLE}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { @@ -24,7 +27,12 @@ impl Cfg { Err(err) => { if err.kind() == std::io::ErrorKind::NotFound { println!("No config file found, creating one"); - let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; + let default_cfg = Cfg { + data: String::from("./"), + apis: Apis { + modrinth: String::from("https://api.modrinth.com/v2/"), + }, + }; let mut file = File::create(devdir(configfile.to_str().unwrap()))?; println!("Created config file"); file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; diff --git a/src/db.rs b/src/db.rs index 2c48cab..09d54c2 100644 --- a/src/db.rs +++ b/src/db.rs @@ -2,17 +2,21 @@ use std::io::{Error, ErrorKind}; use rusqlite::Connection; -use crate::{Modloader, config::Cfg, List, devdir, error::{MLE, MLError, ErrorType}}; +use crate::{ + config::Cfg, + devdir, + error::{ErrorType, MLError, MLE}, + List, Modloader, +}; //MODS pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { - let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; connection.execute( "INSERT INTO mods (id, slug, title) VALUES (?1, ?2, ?3)", - [id, slug, name.replace('\'', "").as_str()] + [id, slug, name.replace('\'', "").as_str()], )?; Ok(()) @@ -21,13 +25,11 @@ pub fn mods_insert(config: Cfg, id: &str, slug: &str, name: &str) -> MLE<()> { pub fn mods_get_all_ids(config: Cfg) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - + let mut mods: Vec = Vec::new(); let mut stmt = connection.prepare("SELECT id FROM mods")?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { mods.push(id?); @@ -49,36 +51,33 @@ pub fn mods_get_all_ids(config: Cfg) -> Result, Box MLE { - //TODO check if "slug" is id let data = devdir(format!("{}/data.db", data).as_str()); let connection = Connection::open(data)?; - + let mut mod_id = String::new(); //get from slug let mut stmt = connection.prepare("SELECT id FROM mods WHERE slug = ?")?; - let id_iter = stmt.query_map([slug], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([slug], |row| row.get::(0))?; for id in id_iter { mod_id = id?; - }; + } //get from title if no id found from slug if mod_id.is_empty() { let mut stmt = connection.prepare("SELECT id FROM mods WHERE title = ?")?; - let id_iter = stmt.query_map([slug], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([slug], |row| row.get::(0))?; for id in id_iter { mod_id = id?; - }; + } } - if mod_id.is_empty() { return Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")) }; + if mod_id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "GI_MOD_NOT_FOUND")); + }; Ok(mod_id) } @@ -91,17 +90,23 @@ pub struct ModInfo { pub fn mods_get_info(config: Cfg, id: &str) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - + let mut mod_info: Option = None; let mut stmt = connection.prepare("SELECT title, slug FROM mods WHERE id = ?")?; let name_iter = stmt.query_map([id], |row| { - Ok(vec![row.get::(0)?, row.get::(1)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + ]) })?; for info in name_iter { let i = info?; - mod_info = Some(ModInfo { title: String::from(&i[0]), slug: String::from(&i[1]) }); - }; + mod_info = Some(ModInfo { + title: String::from(&i[0]), + slug: String::from(&i[1]), + }); + } match mod_info.is_none() { true => Err(MLError::new(ErrorType::DBError, "GN_MOD_NOT_FOUND")), @@ -110,7 +115,6 @@ pub fn mods_get_info(config: Cfg, id: &str) -> MLE { } pub fn mods_remove(config: Cfg, id: String) -> MLE<()> { - println!("Removing mod {} from database", id); let data = devdir(format!("{}/data.db", config.data).as_str()); @@ -131,27 +135,42 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT id, versions, title FROM mods {}", wherestr).as_str())?; + let mut stmt = connection + .prepare(format!("SELECT id, versions, title FROM mods {}", wherestr).as_str())?; let id_iter = stmt.query_map([], |row| { - Ok(vec![row.get::(0)?, row.get::(1)?, row.get::(2)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + row.get::(2)?, + ]) })?; for ver in id_iter { let version = ver?; - println!("\t({}) Get versions from the database", String::from(&version[2])); + println!( + "\t({}) Get versions from the database", + String::from(&version[2]) + ); //println!("Found versions {} for mod {}", version[1], version[0]); - versionmaps.push(DBModlistVersions { mod_id: String::from(&version[0]), versions: String::from(&version[1]) }) - }; + versionmaps.push(DBModlistVersions { + mod_id: String::from(&version[0]), + versions: String::from(&version[1]), + }) + } match versionmaps.is_empty() { true => Err(MLError::new(ErrorType::DBError, "MODS_MODS_NOT_FOUND")), @@ -160,16 +179,37 @@ pub fn mods_get_versions(config: Cfg, mods: Vec) -> MLE, current_link: &str, set_version: bool) -> MLE<()> { +pub fn userlist_insert( + config: Cfg, + list_id: &str, + mod_id: &str, + current_version: &str, + applicable_versions: Vec, + current_link: &str, + set_version: bool, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - + let sv = match set_version { true => "1", false => "0", }; - - connection.execute(format!("INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", list_id).as_str(), [mod_id, current_version, applicable_versions.join("|").as_str(), current_link, sv])?; + + connection.execute( + format!( + "INSERT INTO {} VALUES (?1, ?2, ?3, ?4, 'NONE', ?5)", + list_id + ) + .as_str(), + [ + mod_id, + current_version, + applicable_versions.join("|").as_str(), + current_link, + sv, + ], + )?; Ok(()) } @@ -180,14 +220,12 @@ pub fn userlist_get_all_ids(config: Cfg, list_id: String) -> MLE> { let mut mod_ids: Vec = Vec::new(); let mut stmt = connection.prepare(format!("SELECT mod_id FROM {}", list_id).as_str())?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { //println!("Found id {:?}", id.as_ref().unwrap()); mod_ids.push(id?) - }; + } match mod_ids.is_empty() { true => Err(MLError::new(ErrorType::DBError, "NO_MODS")), @@ -199,24 +237,34 @@ pub fn userlist_remove(config: Cfg, list_id: &str, mod_id: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute(format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), [mod_id])?; + connection.execute( + format!("DELETE FROM {} WHERE mod_id = ?", list_id).as_str(), + [mod_id], + )?; Ok(()) } - -pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { +pub fn userlist_get_applicable_versions( + config: Cfg, + list_id: String, + mod_id: String, +) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection.prepare(format!("SELECT applicable_versions FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([mod_id], |row| { - row.get::(0) - })?; + let mut stmt = connection.prepare( + format!( + "SELECT applicable_versions FROM {} WHERE mod_id = ?", + list_id + ) + .as_str(), + )?; + let ver_iter = stmt.query_map([mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GAV_MOD_NOT_FOUND")), @@ -224,22 +272,31 @@ pub fn userlist_get_applicable_versions(config: Cfg, list_id: String, mod_id: St } } -pub fn userlist_get_all_applicable_versions_with_mods(config: Cfg, list_id: String) -> MLE> { +pub fn userlist_get_all_applicable_versions_with_mods( + config: Cfg, + list_id: String, +) -> MLE> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str())?; + let mut stmt = connection + .prepare(format!("SELECT mod_id, applicable_versions FROM {}", list_id).as_str())?; let id_iter = stmt.query_map([], |row| { - Ok(vec![row.get::(0)?, row.get::(1)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + ]) })?; for ver in id_iter { let out = ver?; versions.push((out[0].to_owned(), out[1].to_owned())); - }; + } - if versions.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; + if versions.is_empty() { + return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); + }; Ok(versions) } @@ -249,14 +306,13 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection.prepare(format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([&mod_id], |row| { - row.get::(0) - })?; + let mut stmt = connection + .prepare(format!("SELECT current_version FROM {} WHERE mod_id = ?", list_id).as_str())?; + let ver_iter = stmt.query_map([&mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GCV_MOD_NOT_FOUND")), @@ -264,63 +320,88 @@ pub fn userlist_get_current_version(config: Cfg, list_id: &str, mod_id: &str) -> } } -pub fn userlist_get_all_current_version_ids(config: Cfg, list_id: String) -> Result, Box> { +pub fn userlist_get_all_current_version_ids( + config: Cfg, + list_id: String, +) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let mut stmt = + connection.prepare(format!("SELECT current_version FROM {}", list_id).as_str())?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { versions.push(id?); - }; + } - if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if versions.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; Ok(versions) } -pub fn userlist_get_all_current_versions_with_mods(config: Cfg, list_id: String) -> Result, Box> { +pub fn userlist_get_all_current_versions_with_mods( + config: Cfg, + list_id: String, +) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut versions: Vec<(String, String)> = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT mod_id, current_version FROM {}", list_id).as_str())?; + let mut stmt = + connection.prepare(format!("SELECT mod_id, current_version FROM {}", list_id).as_str())?; let id_iter = stmt.query_map([], |row| { - Ok(vec![row.get::(0)?, row.get::(1)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + ]) })?; for ver in id_iter { let out = ver?; versions.push((out[0].to_owned(), out[1].to_owned())); - }; + } - if versions.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if versions.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; Ok(versions) } -pub fn userlist_get_set_version(config:Cfg, list_id: &str, mod_id: &str) -> MLE { +pub fn userlist_get_set_version(config: Cfg, list_id: &str, mod_id: &str) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut set_version: bool = false; - let mut stmt = connection.prepare(format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([&mod_id], |row| { - row.get::(0) - })?; + let mut stmt = connection + .prepare(format!("SELECT set_version FROM {} WHERE mod_id = ?", list_id).as_str())?; + let ver_iter = stmt.query_map([&mod_id], |row| row.get::(0))?; for ver in ver_iter { set_version = ver?; - }; + } Ok(set_version) } -pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: String, versions: String, link: String, mod_id: String) -> MLE<()> { +pub fn userlist_change_versions( + config: Cfg, + list_id: String, + current_version: String, + versions: String, + link: String, + mod_id: String, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; @@ -328,33 +409,45 @@ pub fn userlist_change_versions(config: Cfg, list_id: String, current_version: S Ok(()) } -pub fn userlist_add_disabled_versions(config: Cfg, list_id: String, disabled_version: String, mod_id: String) -> MLE<()> { +pub fn userlist_add_disabled_versions( + config: Cfg, + list_id: String, + disabled_version: String, + mod_id: String, +) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - - let currently_disabled_versions = userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; - let disabled_versions = match currently_disabled_versions == "NONE" { + + let currently_disabled_versions = + userlist_get_disabled_versions(config, String::from(&list_id), String::from(&mod_id))?; + let disabled_versions = match currently_disabled_versions == "NONE" { true => disabled_version, false => format!("{}|{}", currently_disabled_versions, disabled_version), }; - - connection.execute(format!("UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", list_id).as_str(), [disabled_versions, mod_id])?; + + connection.execute( + format!( + "UPDATE {} SET disabled_versions = ?1 WHERE mod_id = ?2", + list_id + ) + .as_str(), + [disabled_versions, mod_id], + )?; Ok(()) } -pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: String) -> MLE { +pub fn userlist_get_disabled_versions(config: Cfg, list_id: String, mod_id: String) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut version: String = String::new(); - let mut stmt = connection.prepare(format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id).as_str())?; - let ver_iter = stmt.query_map([mod_id], |row| { - row.get::(0) - })?; + let mut stmt = connection + .prepare(format!("SELECT disabled_versions FROM {} WHERE mod_id = ?", list_id).as_str())?; + let ver_iter = stmt.query_map([mod_id], |row| row.get::(0))?; for ver in ver_iter { version = ver?; - }; + } match version.is_empty() { true => Err(MLError::new(ErrorType::DBError, "GDV_MOD_NOT_FOUND")), @@ -362,36 +455,57 @@ pub fn userlist_get_disabled_versions(config:Cfg, list_id: String, mod_id: Strin } } -pub fn userlist_get_all_downloads(config: Cfg, list_id: String) -> Result, Box> { +pub fn userlist_get_all_downloads( + config: Cfg, + list_id: String, +) -> Result, Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); let mut links: Vec = Vec::new(); - let mut stmt = connection.prepare(format!("SELECT current_download FROM {}", list_id).as_str())?; - let link_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let mut stmt = + connection.prepare(format!("SELECT current_download FROM {}", list_id).as_str())?; + let link_iter = stmt.query_map([], |row| row.get::(0))?; for link in link_iter { let l = link?; println!("Found link {}", String::from(&l)); links.push(l) - }; + } - if links.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_MODS_ON_LIST"))); }; + if links.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_MODS_ON_LIST", + ))); + }; Ok(links) } //lists ///Inserts into lists table and creates new table -pub fn lists_insert(config: Cfg, id: String, mc_version: String, mod_loader: Modloader, download_folder: String) -> MLE<()> { +pub fn lists_insert( + config: Cfg, + id: String, + mc_version: String, + mod_loader: Modloader, + download_folder: String, +) -> MLE<()> { println!("Creating list {}", id); let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute("INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", [id.clone(), mc_version, mod_loader.to_string(), download_folder])?; + connection.execute( + "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", + [ + id.clone(), + mc_version, + mod_loader.to_string(), + download_folder, + ], + )?; connection.execute(format!("CREATE TABLE {}( 'mod_id' TEXT, 'current_version' TEXT, 'applicable_versions' BLOB, 'current_download' TEXT, 'disabled_versions' TEXT DEFAULT 'NONE', 'set_version' INTEGER, CONSTRAINT {}_PK PRIMARY KEY (mod_id) )", id, id).as_str(), [])?; Ok(()) @@ -410,20 +524,37 @@ pub fn lists_get(config: Cfg, list_id: String) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - let mut list = List { id: String::new(), mc_version: String::new(), modloader: Modloader::Fabric, download_folder: String::new() }; - let mut stmt = connection.prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; + let mut list = List { + id: String::new(), + mc_version: String::new(), + modloader: Modloader::Fabric, + download_folder: String::new(), + }; + let mut stmt = connection + .prepare("SELECT mc_version, modloader, download_folder FROM lists WHERE id = ?")?; let list_iter = stmt.query_map([&list_id], |row| { - Ok(vec![row.get::(0)?, row.get::(1)?, row.get::(2)?]) + Ok(vec![ + row.get::(0)?, + row.get::(1)?, + row.get::(2)?, + ]) })?; for l in list_iter { let li = l?; - list = List { id: String::from(&list_id), mc_version: String::from(&li[0]), modloader: Modloader::from(&li[1])?, download_folder: String::from(&li[2]) }; - }; + list = List { + id: String::from(&list_id), + mc_version: String::from(&li[0]), + modloader: Modloader::from(&li[1])?, + download_folder: String::from(&li[2]), + }; + } + + if list.id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "LIST_NOT_FOUND")); + } - if list.id.is_empty() { return Err(MLError::new(ErrorType::DBError, "LIST_NOT_FOUND")); } - Ok(list) } @@ -431,23 +562,24 @@ pub fn lists_version(config: Cfg, list_id: &str, version: &str) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - connection.execute("UPDATE lists SET mc_version = ? WHERE id = ?", [version, list_id])?; + connection.execute( + "UPDATE lists SET mc_version = ? WHERE id = ?", + [version, list_id], + )?; Ok(()) } pub fn lists_get_all_ids(config: Cfg) -> MLE> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - + let mut list_ids: Vec = Vec::new(); let mut stmt = connection.prepare("SELECT id FROM lists")?; - let id_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let id_iter = stmt.query_map([], |row| row.get::(0))?; for id in id_iter { list_ids.push(id?) - }; + } match list_ids.is_empty() { true => Err(MLError::new(ErrorType::DBError, "NO_LISTS")), @@ -460,35 +592,50 @@ pub fn config_change_current_list(config: Cfg, id: String) -> MLE<()> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute("UPDATE user_config SET value = ? WHERE id = 'current_list'", [id])?; + connection.execute( + "UPDATE user_config SET value = ? WHERE id = 'current_list'", + [id], + )?; Ok(()) } pub fn config_get_current_list(config: Cfg) -> MLE { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data).unwrap(); - + let mut list_id = String::new(); let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'current_list'")?; - let list_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let list_iter = stmt.query_map([], |row| row.get::(0))?; for list in list_iter { list_id = list?; - }; + } + + if list_id.is_empty() { + return Err(MLError::new(ErrorType::DBError, "NO_CURRENT_LIST")); + } - if list_id.is_empty() { return Err(MLError::new(ErrorType::DBError, "NO_CURRENT_LIST")); } - Ok(list_id) } //SETUP(UPDATES) -pub fn s_userlist_update_download(config: Cfg, list_id: String, mod_id: String, link: String) -> Result<(), Box> { +pub fn s_userlist_update_download( + config: Cfg, + list_id: String, + mod_id: String, + link: String, +) -> Result<(), Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - connection.execute(format!("UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", list_id).as_str(), [link, mod_id])?; + connection.execute( + format!( + "UPDATE {} SET current_download = ?1 WHERE mod_id = ?2", + list_id + ) + .as_str(), + [link, mod_id], + )?; Ok(()) } @@ -496,7 +643,10 @@ pub fn s_config_create_version(config: Cfg) -> Result<(), Box Result<(), Box Result> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; - + let mut version: String = String::new(); let mut stmt = connection.prepare("SELECT value FROM user_config WHERE id = 'db_version'")?; - let ver_iter = stmt.query_map([], |row| { - row.get::(0) - })?; + let ver_iter = stmt.query_map([], |row| row.get::(0))?; for ver in ver_iter { version = ver?; - }; + } - if version.is_empty() { return Err(Box::new(std::io::Error::new(ErrorKind::Other, "NO_DBVERSION"))); }; + if version.is_empty() { + return Err(Box::new(std::io::Error::new( + ErrorKind::Other, + "NO_DBVERSION", + ))); + }; Ok(version) } -pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: String, default: Option) -> Result<(), Box> { +pub fn s_insert_column( + config: Cfg, + table: String, + column: String, + c_type: String, + default: Option, +) -> Result<(), Box> { let data = devdir(format!("{}/data.db", config.data).as_str()); let connection = Connection::open(data)?; let mut sql = format!("ALTER TABLE {} ADD '{}' {}", table, column, c_type); - + if default.is_some() { sql = format!("{} DEFAULT {}", sql, default.unwrap()); } @@ -541,7 +703,6 @@ pub fn s_insert_column(config: Cfg, table: String, column: String, c_type: Strin } pub fn db_setup(config: Cfg) -> MLE<()> { - println!("Initiating database"); let data = devdir(format!("{}/data.db", config.data).as_str()); @@ -554,6 +715,6 @@ pub fn db_setup(config: Cfg) -> MLE<()> { INSERT INTO 'user_config' VALUES ( 'db_version', '0.5' ); INSERT INTO 'user_config' VALUES ( 'current_list', '...' )", )?; - + Ok(()) } diff --git a/src/error.rs b/src/error.rs index 794a919..bd6e3da 100644 --- a/src/error.rs +++ b/src/error.rs @@ -43,49 +43,70 @@ impl fmt::Display for MLError { ErrorType::LibReq => write!(f, "REQWEST"), ErrorType::LibChrono => write!(f, "Chrono error: {}", self.message), ErrorType::IoError => write!(f, "IO"), - ErrorType::Other => write!(f, "OTHER") + ErrorType::Other => write!(f, "OTHER"), } } } impl From for MLError { fn from(error: reqwest::Error) -> Self { - Self { etype: ErrorType::LibReq, message: error.to_string() } + Self { + etype: ErrorType::LibReq, + message: error.to_string(), + } } } impl From for MLError { fn from(error: toml::de::Error) -> Self { - Self { etype: ErrorType::LibToml, message: error.to_string() } + Self { + etype: ErrorType::LibToml, + message: error.to_string(), + } } } impl From for MLError { fn from(error: rusqlite::Error) -> Self { - Self { etype: ErrorType::LibSql, message: error.to_string() } + Self { + etype: ErrorType::LibSql, + message: error.to_string(), + } } } impl From for MLError { fn from(error: toml::ser::Error) -> Self { - Self { etype: ErrorType::LibToml, message: error.to_string() } + Self { + etype: ErrorType::LibToml, + message: error.to_string(), + } } } impl From for MLError { fn from(error: chrono::ParseError) -> Self { - Self { etype: ErrorType::LibChrono, message: error.to_string() } + Self { + etype: ErrorType::LibChrono, + message: error.to_string(), + } } } impl From for MLError { fn from(error: std::io::Error) -> Self { - Self { etype: ErrorType::IoError, message: error.to_string() } + Self { + etype: ErrorType::IoError, + message: error.to_string(), + } } } impl MLError { pub fn new(etype: ErrorType, message: &str) -> Self { - Self { etype, message: String::from(message) } + Self { + etype, + message: String::from(message), + } } } diff --git a/src/files.rs b/src/files.rs index 6519c6a..6160cb4 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,11 +1,20 @@ -use std::{fs::{File, read_dir, remove_file, rename}, io::Write, collections::HashMap}; use futures_util::StreamExt; use reqwest::Client; - -use crate::{List, modrinth::Version, db::{userlist_add_disabled_versions, mods_get_info}, config::Cfg, error::{MLE, MLError, ErrorType}}; +use std::{ + collections::HashMap, + fs::{read_dir, remove_file, rename, File}, + io::Write, +}; + +use crate::{ + config::Cfg, + db::{mods_get_info, userlist_add_disabled_versions}, + error::{ErrorType, MLError, MLE}, + modrinth::Version, + List, +}; pub async fn download_versions(list: List, config: Cfg, versions: Vec) -> MLE { - let dl_path = String::from(&list.download_folder); println!(" └Download mods to {}", dl_path); @@ -21,7 +30,13 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) Ok(e) => e, Err(..) => return Err(MLError::new(ErrorType::Other, "NO_FILE_EXTENSION")), }; - let filename = format!("{}.mr.{}.{}.{}", splitname.join("."), ver.project_id, ver.id, extension); + let filename = format!( + "{}.mr.{}.{}.{}", + splitname.join("."), + ver.project_id, + ver.id, + extension + ); download_file(primary_file.url, list.clone().download_folder, filename).await?; //tokio::time::sleep(std::time::Duration::new(3, 0)).await; println!(" ✓"); @@ -32,10 +47,7 @@ pub async fn download_versions(list: List, config: Cfg, versions: Vec) async fn download_file(url: String, path: String, name: String) -> MLE<()> { let dl_path_file = format!("{}/{}", path, name); - let res = Client::new() - .get(String::from(&url)) - .send() - .await?; + let res = Client::new().get(String::from(&url)).send().await?; // download chunks let mut file = File::create(&dl_path_file)?; @@ -49,7 +61,12 @@ async fn download_file(url: String, path: String, name: String) -> MLE<()> { Ok(()) } -pub fn disable_version(config: Cfg, current_list: List, versionid: String, mod_id: String) -> MLE<()> { +pub fn disable_version( + config: Cfg, + current_list: List, + versionid: String, + mod_id: String, +) -> MLE<()> { //println!("Disabling version {} for mod {}", versionid, mod_id); let file = get_file_path(current_list.clone(), String::from(&versionid))?; let disabled = format!("{}.disabled", file); @@ -63,7 +80,7 @@ pub fn disable_version(config: Cfg, current_list: List, versionid: String, mod_i pub fn delete_version(list: List, version: String) -> MLE<()> { let file = get_file_path(list, version)?; - + remove_file(file)?; Ok(()) @@ -76,19 +93,24 @@ pub fn get_file_path(list: List, versionid: String) -> MLE { if path.is_file() { let pathstr = match path.to_str().ok_or("") { Ok(s) => s, - Err(..) => return Err(MLError::new(ErrorType::Other, "INVALID_PATH")) + Err(..) => return Err(MLError::new(ErrorType::Other, "INVALID_PATH")), }; let namesplit: Vec<&str> = pathstr.split('.').collect(); let ver_id = namesplit[namesplit.len() - 2]; names.insert(String::from(ver_id), String::from(pathstr)); } - }; + } let filename = match names.get(&versionid).ok_or("") { Ok(n) => n, - Err(..) => return Err(MLError::new(ErrorType::ArgumentError, "VERSION_NOT_FOUND_IN_FILES")) + Err(..) => { + return Err(MLError::new( + ErrorType::ArgumentError, + "VERSION_NOT_FOUND_IN_FILES", + )) + } }; - + Ok(filename.to_owned()) } @@ -99,7 +121,10 @@ pub fn get_downloaded_versions(list: List) -> MLE> { if path.is_file() && path.extension().ok_or("BAH").unwrap() == "jar" { let pathstr = path.to_str().ok_or("BAH").unwrap(); let namesplit: Vec<&str> = pathstr.split('.').collect(); - versions.insert(String::from(namesplit[namesplit.len() - 3]), String::from(namesplit[namesplit.len() - 2])); + versions.insert( + String::from(namesplit[namesplit.len() - 3]), + String::from(namesplit[namesplit.len() - 2]), + ); } } Ok(versions) @@ -111,6 +136,6 @@ pub fn clean_list_dir(list: &List) -> MLE<()> { for entry in std::fs::read_dir(dl_path)? { let entry = entry?; std::fs::remove_file(entry.path())?; - }; + } Ok(()) } diff --git a/src/lib.rs b/src/lib.rs index 9db907d..43f0fe7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,20 +1,20 @@ pub mod apis; -pub mod config; pub mod commands; +pub mod config; pub mod db; pub mod error; pub mod files; -use std::{path::Path, fmt::Display}; +use std::{fmt::Display, path::Path}; pub use apis::*; pub use commands::*; -use error::{MLE, ErrorType, MLError}; +use error::{ErrorType, MLError, MLE}; #[derive(Debug, Clone, PartialEq, Eq)] pub enum Modloader { Fabric, - Forge + Forge, } impl Modloader { @@ -22,7 +22,7 @@ impl Modloader { match string { "forge" => Ok(Modloader::Forge), "fabric" => Ok(Modloader::Fabric), - _ => Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER")) + _ => Err(MLError::new(ErrorType::ArgumentError, "UNKNOWN_MODLOADER")), } } } diff --git a/src/main.rs b/src/main.rs index e845be1..eb5ee0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,10 @@ use clap::{Parser, Subcommand}; -use modlist::{config::Cfg, mod_add, mod_remove, db::{lists_get, config_get_current_list, lists_get_all_ids}, IDSelector, download, update, List, get_current_list, import, devdir, export, list_add, Modloader, list_version, list_remove, list_change}; +use modlist::{ + config::Cfg, + db::{config_get_current_list, lists_get, lists_get_all_ids}, + devdir, download, export, get_current_list, import, list_add, list_change, list_remove, + list_version, mod_add, mod_remove, update, IDSelector, List, Modloader, +}; //TODO make default list optional #[derive(Parser)] @@ -17,13 +22,13 @@ enum Commands { }, List { #[command(subcommand)] - command: ListCommands + command: ListCommands, }, Download { /// download all lists #[arg(short, long)] all: bool, - + /// clean all mods before downloading them #[arg(short, long)] clean: bool, @@ -36,11 +41,11 @@ enum Commands { /// download all lists #[arg(short, long)] all: bool, - + /// directly download updated mods #[arg(short, long)] download: bool, - + /// clean all mods before downloading them #[arg(short, long)] clean: bool, @@ -59,7 +64,7 @@ enum Commands { }, Export { /// the list you want to export - list: Option + list: Option, }, } @@ -68,7 +73,7 @@ enum ModCommands { Add { /// id of the mod/version id: String, - + /// set id mode to version #[arg(short, long)] version: bool, @@ -83,7 +88,7 @@ enum ModCommands { /// optional List selection, else default list will be used #[arg(short, long)] - list: Option + list: Option, }, Remove { /// id, name or title of the mod @@ -91,8 +96,8 @@ enum ModCommands { /// optional List selection, else default list will be used #[arg(short, long)] - list: Option - } + list: Option, + }, } #[derive(Subcommand)] @@ -109,12 +114,12 @@ enum ListCommands { }, Remove { /// id, name or title of the list - id: String + id: String, }, List, Change { /// id of the list to change to - id: String + id: String, }, Version { /// list id @@ -129,12 +134,11 @@ enum ListCommands { /// delete disabled versions #[arg(short, long)] remove: bool, - } + }, } #[tokio::main] async fn main() { - let cli = Cli::parse(); let config = Cfg::init("modlist.toml").unwrap(); @@ -143,13 +147,22 @@ async fn main() { //TODO setup? maybe setup on install match cli.command { Commands::Mod { command } => { - match command { #[allow(unused_variables)] - ModCommands::Add { id, version, list, download, lock } => { + ModCommands::Add { + id, + version, + list, + download, + lock, + } => { let listf = match list { Some(list) => lists_get(config.clone(), list).unwrap(), - None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + None => lists_get( + config.clone(), + config_get_current_list(config.clone()).unwrap(), + ) + .unwrap(), }; let marked_id = match version { @@ -164,15 +177,24 @@ async fn main() { //TODO add success even if no file found let listf = match list { Some(list) => lists_get(config.clone(), list).unwrap(), - None => lists_get(config.clone(), config_get_current_list(config.clone()).unwrap()).unwrap(), + None => lists_get( + config.clone(), + config_get_current_list(config.clone()).unwrap(), + ) + .unwrap(), }; mod_remove(config, &id, listf) } } - }, + } Commands::List { command } => { match command { - ListCommands::Add { id, directory, modloader, version } => { + ListCommands::Add { + id, + directory, + modloader, + version, + } => { let ml = match modloader { Some(ml) => Modloader::from(&ml).unwrap(), //TODO add default modloader to config @@ -187,23 +209,27 @@ async fn main() { }; list_add(config, id, ver, ml, directory) - }, - ListCommands::Remove { id } => { - list_remove(config, id) - }, + } + ListCommands::Remove { id } => list_remove(config, id), ListCommands::List => { todo!() - }, - ListCommands::Change { id } => { - list_change(config, id) - }, - ListCommands::Version { id, version, download, remove } => { - list_version(config, id, version, download, remove).await } + ListCommands::Change { id } => list_change(config, id), + ListCommands::Version { + id, + version, + download, + remove, + } => list_version(config, id, version, download, remove).await, } - }, + } //TODO a add specific list - Commands::Update { all, download, clean, remove } => { + Commands::Update { + all, + download, + clean, + remove, + } => { let mut liststack: Vec = vec![]; if all { let list_ids = lists_get_all_ids(config.clone()).unwrap(); @@ -216,21 +242,26 @@ async fn main() { liststack.push(current) } update(config, liststack, clean, download, remove).await - }, + } //TODO add specific list - Commands::Download { all, clean, remove } => { - download(config, all, clean, remove).await - }, + Commands::Download { all, clean, remove } => download(config, all, clean, remove).await, Commands::Import { file, download } => { let filestr: String = match file { Some(args) => args, - None => devdir(dirs::home_dir().unwrap().join("mlexport.toml").into_os_string().into_string().unwrap().as_str()), + None => devdir( + dirs::home_dir() + .unwrap() + .join("mlexport.toml") + .into_os_string() + .into_string() + .unwrap() + .as_str(), + ), }; import(config, filestr, download).await - }, - Commands::Export { list } => { - export(config, list) - }, - }.unwrap(); + } + Commands::Export { list } => export(config, list), + } + .unwrap(); } -- cgit v1.2.3 From 64958cc9ff0858dbf068625e35b8d5dae249d4a4 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Sun, 23 Apr 2023 14:11:01 +0200 Subject: added todo --- src/main.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.rs b/src/main.rs index eb5ee0b..2006856 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,8 @@ use modlist::{ list_version, mod_add, mod_remove, update, IDSelector, List, Modloader, }; +//TODO implement remote sql db + //TODO make default list optional #[derive(Parser)] #[command(author, version, about)] -- cgit v1.2.3