From 2d7e0a2fbf1c8a4187e2bf3fdcd592631ab273a0 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Fri, 26 May 2023 17:40:27 +0200 Subject: added full progress? cargo fmt --- Cargo.lock | 325 ++++++++++++++++--------------------------- src/apis/modrinth.rs | 7 +- src/commands/download.rs | 39 ++++-- src/commands/io.rs | 34 ++++- src/commands/list.rs | 54 ++++--- src/commands/modification.rs | 114 +++++++-------- src/commands/update.rs | 95 ++++++++----- src/config.rs | 6 +- src/db.rs | 41 +++--- src/error.rs | 6 +- src/files.rs | 77 ++++++---- src/lib.rs | 46 +++--- src/main.rs | 164 +++++++++++----------- 13 files changed, 526 insertions(+), 482 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39a163c..c72ac69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,11 +19,11 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ - "getrandom", + "cfg-if", "once_cell", "version_check", ] @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6342bd4f5a1205d7f41e94a41a901f5647c938cdfa96036338e8533c9d6c2450" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" dependencies = [ "anstyle", "anstyle-parse", @@ -109,9 +109,9 @@ dependencies = [ [[package]] name = "base64" -version = "0.21.0" +version = "0.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "604178f6c5c21f02dc555784810edfb88d34ac2c73b2eae109655649ee73ce3d" [[package]] name = "bitflags" @@ -121,15 +121,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.2.1" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" +checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84" [[package]] name = "bumpalo" -version = "3.12.1" +version = "3.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1ce199063694f33ffb7dd4e0ee620741495c32833cde5aa08f02a0bf96f0c8" +checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" [[package]] name = "bytes" @@ -166,9 +166,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.4" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" +checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc" dependencies = [ "clap_builder", "clap_derive", @@ -177,9 +177,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.4" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" +checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990" dependencies = [ "anstream", "anstyle", @@ -190,40 +190,30 @@ dependencies = [ [[package]] name = "clap_complete" -version = "4.2.1" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a19591b2ab0e3c04b588a0e04ddde7b9eaa423646d1b4a8092879216bf47473" +checksum = "a04ddfaacc3bc9e6ea67d024575fafc2a813027cf374b8f24f7bc233c6b6be12" dependencies = [ "clap", ] [[package]] name = "clap_derive" -version = "4.2.0" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" +checksum = "191d9573962933b4027f932c600cd252ce27a8ad5979418fe78e43c07996f27b" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[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" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" [[package]] name = "colorchoice" @@ -233,9 +223,9 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "console" -version = "0.15.6" +version = "0.15.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0525278dce688103060006713371cedbad27186c7d913f33d866b498da0f595" +checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" dependencies = [ "encode_unicode", "lazy_static", @@ -260,68 +250,25 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" -[[package]] -name = "cxx" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f61f1b6389c3fe1c316bf8a4dccc90a38208354b330925bce1f74a6c4756eb93" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2", - "quote", - "scratch", - "syn 2.0.15", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7944172ae7e4068c533afbb984114a56c46e9ccddda550499caa222902c7f7bb" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.15", -] - [[package]] name = "dirs" -version = "5.0.0" +version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dece029acd3353e3a58ac2e3eb3c8d6c35827a892edc6cc4138ef9c33df46ecd" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ "dirs-sys", ] [[package]] name = "dirs-sys" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04414300db88f70d74c5ff54e50f9e1d1737d9a5b90f53fcf2e95ca2a9ab554b" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ "libc", + "option-ext", "redox_users", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -450,7 +397,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -501,9 +448,9 @@ checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" [[package]] name = "h2" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17f8a914c2987b688368b5138aa05321db91f4090cf26118185672ad588bce21" +checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" dependencies = [ "bytes", "fnv", @@ -523,17 +470,23 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ "ahash", ] [[package]] name = "hashlink" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69fe1fcf8b4278d860ad0548329f892a3631fb63f82574df68275f34cdbe0ffa" +checksum = "0761a1b9491c4f2e3d66aa0f62d0fba0af9a0e2852e4d48ea506632a4b56e6aa" dependencies = [ - "hashbrown", + "hashbrown 0.13.2", ] [[package]] @@ -644,12 +597,11 @@ dependencies = [ [[package]] name = "iana-time-zone-haiku" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" dependencies = [ - "cxx", - "cxx-build", + "cc", ] [[package]] @@ -669,7 +621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", ] [[package]] @@ -695,9 +647,9 @@ dependencies = [ [[package]] name = "io-lifetimes" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" dependencies = [ "hermit-abi 0.3.1", "libc", @@ -730,9 +682,9 @@ checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" dependencies = [ "wasm-bindgen", ] @@ -745,9 +697,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.142" +version = "0.2.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" [[package]] name = "libsqlite3-sys" @@ -760,20 +712,11 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "link-cplusplus" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] - [[package]] name = "linux-raw-sys" -version = "0.3.4" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" [[package]] name = "lock_api" @@ -937,7 +880,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -958,6 +901,12 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "parking_lot" version = "0.12.1" @@ -1001,9 +950,9 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.26" +version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" +checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" [[package]] name = "portable-atomic" @@ -1022,18 +971,18 @@ checksum = "dc59d1bcc64fc5d021d67521f818db868368028108d37f0e98d74e33f68297b5" [[package]] name = "proc-macro2" -version = "1.0.56" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] @@ -1069,9 +1018,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.16" +version = "0.11.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "cde824a14b7c14f85caff81225f411faacc04a2013f41670f41443742b1c1c55" dependencies = [ "base64", "bytes", @@ -1112,7 +1061,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "549b9d036d571d42e6e85d1c1425e2ac83491075078ca9a15be021c56b1641f2" dependencies = [ - "bitflags 2.2.1", + "bitflags 2.3.1", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -1128,9 +1077,9 @@ checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" [[package]] name = "rustix" -version = "0.37.15" +version = "0.37.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0661814f891c57c930a610266415528da53c4933e6dea5fb350cbfe048a9ece" +checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" dependencies = [ "bitflags 1.3.2", "errno", @@ -1161,17 +1110,11 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" -[[package]] -name = "scratch" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" - [[package]] name = "security-framework" -version = "2.8.2" +version = "2.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" dependencies = [ "bitflags 1.3.2", "core-foundation", @@ -1182,9 +1125,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" dependencies = [ "core-foundation-sys", "libc", @@ -1192,22 +1135,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.160" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -1223,9 +1166,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0efd8caf556a6cebd3b285caf480045fcc1ac04f6bd786b09a6f11af30c4fcf4" +checksum = "93107647184f6027e3b7dcb2e11034cf95ffa1e3a682c67951963ac69c1c007d" dependencies = [ "serde", ] @@ -1284,20 +1227,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.109" +version = "2.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "syn" -version = "2.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" +checksum = "45b6ddbb36c5b969c182aec3c4a0bce7df3fbad4b77114706a49aacc80567388" dependencies = [ "proc-macro2", "quote", @@ -1317,15 +1249,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "termcolor" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" -dependencies = [ - "winapi-util", -] - [[package]] name = "thiserror" version = "1.0.40" @@ -1343,7 +1266,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -1374,9 +1297,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.28.0" +version = "1.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" +checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" dependencies = [ "autocfg", "bytes", @@ -1399,7 +1322,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.15", + "syn", ] [[package]] @@ -1428,9 +1351,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b403acf6f2bb0859c93c7f0d967cb4a75a7ac552100f9322faf64dc047669b21" +checksum = "d6135d499e69981f9ff0ef2167955a5333c35e36f6937d382974566b3d5b94ec" dependencies = [ "serde", "serde_spanned", @@ -1440,18 +1363,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ab8ed2edee10b50132aed5f331333428b011c99402b5a534154ed15746f9622" +checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.19.8" +version = "0.19.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "239410c8609e8125456927e6707163a3b1fdb40561e4b803bc041f466ccfdc13" +checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739" dependencies = [ "indexmap", "serde", @@ -1468,19 +1391,20 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.38" +version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9cf6a813d3f40c88b0b6b6f29a5c95c6cdbf97c1f9cc53fb820200f5ad814d" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" dependencies = [ + "cfg-if", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.30" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" dependencies = [ "once_cell", ] @@ -1499,9 +1423,9 @@ checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" [[package]] name = "unicode-normalization" @@ -1571,9 +1495,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1581,24 +1505,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "2d1985d03709c53167ce907ff394f5316aa22cb4e12761295c5dc57dacb6297e" dependencies = [ "cfg-if", "js-sys", @@ -1608,9 +1532,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1618,22 +1542,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" [[package]] name = "wasm-streams" @@ -1650,9 +1574,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" dependencies = [ "js-sys", "wasm-bindgen", @@ -1674,15 +1598,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -1847,9 +1762,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "winnow" -version = "0.4.1" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae8970b36c66498d8ff1d66685dc86b91b29db0c7739899012f63a63814b4b28" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" dependencies = [ "memchr", ] diff --git a/src/apis/modrinth.rs b/src/apis/modrinth.rs index 14ff266..fb3952d 100644 --- a/src/apis/modrinth.rs +++ b/src/apis/modrinth.rs @@ -127,7 +127,7 @@ pub enum GameVersionType { release, snapshot, alpha, - beta + beta, } async fn get(api: &str, path: &str) -> Result>, Box> { @@ -208,7 +208,10 @@ pub fn extract_current_version(versions: Vec) -> MLE { } pub async fn get_game_versions() -> Vec { - let data = get("https://api.modrinth.com/v2/", "tag/game_version").await.unwrap().unwrap(); + let data = get("https://api.modrinth.com/v2/", "tag/game_version") + .await + .unwrap() + .unwrap(); serde_json::from_slice(&data).unwrap() } diff --git a/src/commands/download.rs b/src/commands/download.rs index 7aa0156..dd00ffb 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,7 +1,5 @@ +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; -use indicatif::{MultiProgress, ProgressStyle, ProgressBar}; - -use crate::{STYLE_BAR_POS, PROGRESS_CHARS}; use crate::{config::Cfg, List}; use crate::{ db::userlist_get_all_current_versions_with_mods, @@ -11,12 +9,21 @@ use crate::{ }, modrinth::get_raw_versions, }; - -pub async fn download(config: &Cfg, liststack: Vec, clean: bool, delete_old: bool) -> MLE<()> { - +use crate::{PROGRESS_CHARS, STYLE_BAR_POS}; + +pub async fn download( + config: &Cfg, + liststack: Vec, + clean: bool, + delete_old: bool, +) -> MLE<()> { let mp = MultiProgress::new(); let download_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); - download_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + download_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); for current_list in liststack { download_p.set_message(format!("Download in {}", current_list.id)); @@ -67,17 +74,27 @@ pub async fn download(config: &Cfg, liststack: Vec, clean: bool, delete_ol ) .await?; } else { - download_p.println(format!("There are no new versions to download for {}", current_list.id)); + download_p.println(format!( + "There are no new versions to download for {}", + current_list.id + )); } if !to_disable.is_empty() { - let d_p = mp.insert_before(&download_p, ProgressBar::new(to_disable.len().try_into().unwrap())); - d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + let d_p = mp.insert_before( + &download_p, + ProgressBar::new(to_disable.len().try_into().unwrap()), + ); + d_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); for ver in to_disable { if delete_old { d_p.set_message(format!("Delete version {}", ver.1)); d_p.inc(1); - delete_version(current_list.clone(), ver.1)?; + delete_version(¤t_list, ver.1)?; } else { d_p.set_message(format!("Disable version {}", ver.1)); d_p.inc(1); diff --git a/src/commands/io.rs b/src/commands/io.rs index 45e363e..2501583 100644 --- a/src/commands/io.rs +++ b/src/commands/io.rs @@ -1,12 +1,16 @@ +use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::prelude::*; use crate::{ config::Cfg, - db::{lists_get, lists_get_all_ids, lists_insert, userlist_get_set_version, userlist_get_all_ids, userlist_get_current_version}, + db::{ + lists_get, lists_get_all_ids, lists_insert, userlist_get_all_ids, + userlist_get_current_version, userlist_get_set_version, + }, error::MLE, - mod_add, IDSelector, List, Modloader, AddMod, + mod_add, AddMod, IDSelector, List, Modloader, STYLE_OPERATION, }; #[derive(Debug, Serialize, Deserialize)] @@ -17,14 +21,14 @@ struct Export { #[derive(Debug, Serialize, Deserialize)] struct ExportVersion { version: String, - set: bool + set: bool, } impl ExportVersion { fn from(config: &Cfg, list_id: &str, mod_id: &str) -> MLE { Ok(Self { version: userlist_get_current_version(config, list_id, mod_id)?, - set: userlist_get_set_version(config, list_id, mod_id)? + set: userlist_get_set_version(config, list_id, mod_id)?, }) } } @@ -64,23 +68,36 @@ impl ExportList { } pub fn export(config: &Cfg, list: Option) -> MLE<()> { + let progress = ProgressBar::new_spinner(); + progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + let mut list_ids: Vec = vec![]; if list.is_none() { list_ids = lists_get_all_ids(config)?; } else { list_ids.push(lists_get(config, &list.unwrap())?.id); } + let mut lists: Vec = vec![]; for list_id in list_ids { + progress.set_message(format!("Export {}", list_id)); + //TODO download option/ new download on import lists.push(ExportList::from(config, &list_id, true)?); } let toml = toml::to_string(&Export { lists })?; - let filestr = dirs::home_dir().unwrap().join("mlexport.toml"); + let filestr = dirs::home_dir() + .unwrap() + .join("mlexport.toml") + .into_os_string() + .into_string() + .unwrap(); - let mut file = File::create(filestr.into_os_string().into_string().unwrap().as_str())?; + progress.set_message("Create file"); + let mut file = File::create(&filestr)?; file.write_all(toml.as_bytes())?; + progress.finish_with_message(format!("Exported to {}", filestr)); Ok(()) } @@ -108,7 +125,10 @@ pub async fn import(config: &Cfg, file_str: &str, direct_download: bool) -> MLE< let mut ver_ids = vec![]; for id in exportlist.versions { - ver_ids.push(AddMod { id: IDSelector::VersionID(id.version), set_version: id.set} ); + ver_ids.push(AddMod { + id: IDSelector::VersionID(id.version), + set_version: id.set, + }); } mod_add(config, ver_ids, list, direct_download).await?; } diff --git a/src/commands/list.rs b/src/commands/list.rs index 52f14f2..b0a082d 100644 --- a/src/commands/list.rs +++ b/src/commands/list.rs @@ -1,11 +1,13 @@ +use indicatif::{ProgressBar, ProgressStyle}; + use crate::{ config::Cfg, db::{ - config_change_current_list, config_get_current_list, lists_get, lists_insert, lists_remove, - lists_version, lists_get_all_ids, + config_change_current_list, config_get_current_list, lists_get, lists_get_all_ids, + lists_insert, lists_remove, lists_version, }, - error::{MLE, MLError, ErrorType}, - update, Modloader, + error::{ErrorType, MLError, MLE}, + update, Modloader, STYLE_OPERATION, }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -28,20 +30,35 @@ pub fn list_add( modloader: &Modloader, directory: &str, ) -> MLE<()> { - lists_insert(config, id, mc_version, modloader, directory) + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Create {}", id)); + lists_insert(config, id, mc_version, modloader, directory)?; + p.finish_with_message(format!("Created {}", id)); + Ok(()) } -pub fn list_change(config: &Cfg, id: String) -> MLE<()> { +pub fn list_change(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Change default list to {}", id)); + if !lists_get_all_ids(config)?.into_iter().any(|l| l == id) { return Err(MLError::new(ErrorType::ArgumentError, "List not found")); }; - println!("Change default list to: {}", id); - config_change_current_list(config, id) + config_change_current_list(config, id)?; + + p.finish_with_message(format!("Changed default list to {}", id)); + Ok(()) } -pub fn list_remove(config: &Cfg, id: String) -> MLE<()> { - //TODO add logging - lists_remove(config, id) +pub fn list_remove(config: &Cfg, id: &str) -> MLE<()> { + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!("Remove {}", id)); + lists_remove(config, id)?; + p.finish_with_message(format!("Removed {}", id)); + Ok(()) } ///Changing the current lists version and updating it @@ -57,17 +74,20 @@ pub async fn list_version( download: bool, delete: bool, ) -> MLE<()> { - println!( + let p = ProgressBar::new_spinner(); + p.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + p.set_message(format!( "Change version for list {} to minecraft version: {}", id, mc_version - ); + )); lists_version(config, id, &mc_version)?; - println!( - "\nCheck for updates for new minecraft version in list {}", - id - ); + p.finish_with_message(format!( + "Changed version for list {} to minecraft version: {}", + id, mc_version + )); + let list = lists_get(config, id)?; update(config, vec![list], true, download, delete).await } diff --git a/src/commands/modification.rs b/src/commands/modification.rs index 8abf913..fdb70c7 100644 --- a/src/commands/modification.rs +++ b/src/commands/modification.rs @@ -1,23 +1,23 @@ -use std::{io::Write, collections::HashMap}; +use std::collections::HashMap; -use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 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, mods_get_info, + lists_get_all_ids, mods_get_id, mods_get_info, 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, PROGRESS_CHARS, STYLE_BAR_POS, + List, PROGRESS_CHARS, STYLE_BAR_POS, STYLE_OPERATION, }; #[derive(Debug)] pub struct AddMod { pub id: IDSelector, - pub set_version: bool + pub set_version: bool, } #[derive(Debug, PartialEq, Eq)] @@ -47,9 +47,13 @@ pub async fn mod_add( let mut mod_ids: Vec<(String, bool)> = Vec::new(); let mut ver_ids: Vec<(String, bool)> = Vec::new(); - + let add_p = mp.add(ProgressBar::new(mods.len().try_into().unwrap())); - add_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + add_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); add_p.set_message("Sort ids"); //"Sort" project ids from version ids to be able to handle them differently but in a batch @@ -62,7 +66,7 @@ pub async fn mod_add( } add_p.set_message("Get infos"); - + let mut projectinfo: Vec = Vec::new(); if !mod_ids.is_empty() { projectinfo.append(&mut get_mod_infos(config, mod_ids, list.clone()).await?); @@ -80,11 +84,17 @@ pub async fn mod_add( let mut downloadstack: Vec = Vec::new(); //Adding each mod to the lists and downloadstack - let project_p = mp.insert_before(&add_p, ProgressBar::new(projectinfo.len().try_into().unwrap())); - project_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + let project_p = mp.insert_before( + &add_p, + ProgressBar::new(projectinfo.len().try_into().unwrap()), + ); + project_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); for project in projectinfo { - project_p.set_message(format!("Add {}", project.title)); let current_version_id = if project.current_version.is_none() { @@ -116,12 +126,7 @@ pub async fn mod_add( Ok(..) => Ok(..), }?; - match mods_insert( - config, - &project.mod_id, - &project.slug, - &project.title, - ) { + match mods_insert(config, &project.mod_id, &project.slug, &project.title) { Err(e) => { if e.to_string() == "SQL: UNIQUE constraint failed: mods.id" { Ok(..) @@ -152,8 +157,11 @@ pub async fn mod_add( Ok(()) } -async fn get_mod_infos(config: &Cfg, mod_ids: Vec<(String, bool)>, list: List) -> MLE> { - +async fn get_mod_infos( + config: &Cfg, + mod_ids: Vec<(String, bool)>, + list: List, +) -> MLE> { let mut setmap: HashMap = HashMap::new(); let mut ids = vec![]; @@ -197,19 +205,15 @@ async fn get_mod_infos(config: &Cfg, mod_ids: Vec<(String, bool)>, list: List) - .find(|v| v.id == current_id) .unwrap(), ); - + // match primary, if none? - let files = current_version - .clone() - .ok_or("") - .unwrap() - .files; + let files = current_version.clone().ok_or("").unwrap().files; file = match files.clone().into_iter().find(|f| f.primary) { - Some(f) => f, - None => { files[0].clone() } - } - .url; + Some(f) => f, + None => files[0].clone(), + } + .url; for ver in available_versions { available_versions_vec.push(ver.id); @@ -247,7 +251,6 @@ async fn get_mod_infos(config: &Cfg, mod_ids: Vec<(String, bool)>, list: List) - } async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE> { - let mut setmap: HashMap = HashMap::new(); let mut ids = vec![]; @@ -271,15 +274,13 @@ async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE f, - None => { files[0].clone() } - } - .url; + Some(f) => f, + None => files[0].clone(), + } + .url; projectinfo.push(ProjectInfo { mod_id: String::from(&project.id), @@ -300,34 +301,31 @@ async fn get_ver_info(config: &Cfg, ver_ids: Vec<(String, bool)>) -> MLE MLE<()> { +pub fn mod_remove(config: &Cfg, id: &str, list: &List) -> MLE<()> { + let progress = ProgressBar::new_spinner(); + progress.set_style(ProgressStyle::with_template(STYLE_OPERATION).unwrap()); + let mod_id = mods_get_id(&config.data, id)?; - println!("Remove mod {} from {}", mods_get_info(config, &mod_id)?.title, list.id); + let info = mods_get_info(config, &mod_id)?; + + progress.set_message(format!("Remove {} from {}", info.title, list.id)); + let version = userlist_get_current_version(config, &list.id, &mod_id)?; - print!(" └Remove from list"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; userlist_remove(config, &list.id, &mod_id)?; - println!(" ✓"); - print!(" └Delete file"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; + progress.set_message("Delete file"); match delete_version(list, version) { Ok(_) => (), Err(err) => { - if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { + if err.to_string() != "User input not accepted: VERSION_NOT_FOUND_IN_FILES" { return Err(err); }; - }, + } }; - println!(" ✓"); - print!(" └Clean main db table"); - //Force flush of stdout, else print! doesn't print instantly - std::io::stdout().flush()?; + progress.set_message("Check main list"); let list_ids = lists_get_all_ids(config)?; // Remove mod from main list if not used elsewhere @@ -336,11 +334,11 @@ pub fn mod_remove(config: &Cfg, id: &str, list: List) -> MLE<()> { let mods = match userlist_get_all_ids(config, &id) { Ok(m) => m, Err(err) => { - if err.to_string() == "Database: NO_MODS_USERLIST" { + if err.to_string() == "Database: NO_MODS_USERLIST" { println!(" ✓"); return Ok(()); }; - return Err(err) + return Err(err); } }; if mods.contains(&mod_id) { @@ -350,9 +348,11 @@ pub fn mod_remove(config: &Cfg, id: &str, list: List) -> MLE<()> { } if !mod_used { - mods_remove(config, mod_id)?; + progress.set_message("Remove from main list"); + mods_remove(config, &mod_id)?; }; - println!(" ✓"); + + progress.finish_with_message(format!("Removed {} from {}", info.title, list.id)); Ok(()) } diff --git a/src/commands/update.rs b/src/commands/update.rs index 194bbe5..3aae002 100644 --- a/src/commands/update.rs +++ b/src/commands/update.rs @@ -1,4 +1,4 @@ -use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use crate::{ config::Cfg, @@ -19,11 +19,14 @@ pub async fn update( direct_download: bool, delete_old: bool, ) -> MLE<()> { - let mp = MultiProgress::new(); let update_p = mp.add(ProgressBar::new(liststack.len().try_into().unwrap())); - update_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + update_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); for current_list in liststack { update_p.set_message(format!("Update {}", current_list.id)); @@ -35,7 +38,11 @@ pub async fn update( let mods = userlist_get_all_ids(config, ¤t_list.id)?; let list_u_p = mp.insert_before(&list_p, ProgressBar::new(mods.len().try_into().unwrap())); - list_u_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + list_u_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); let mut current_versions: Vec<(String, String)> = vec![]; let mut updatestack: Vec = vec![]; @@ -43,7 +50,7 @@ pub async fn update( for id in mods { let info = mods_get_info(config, &id)?; list_u_p.set_message(format!("Update {}", info.title)); - + //Skip check if version is set if userlist_get_set_version(config, ¤t_list.id, &id)? { list_u_p.inc(1); @@ -51,19 +58,10 @@ pub async fn update( } //Getting current installed version for disable or delete - let disable_version = - userlist_get_current_version(config, ¤t_list.id, &id)?; + let disable_version = userlist_get_current_version(config, ¤t_list.id, &id)?; updatestack.push( - match specific_update( - config, - clean, - current_list.clone(), - &id, - &list_u_p - ) - .await - { + match specific_update(config, clean, current_list.clone(), &id, &list_u_p).await { Ok(ver) => { current_versions.push((disable_version, id)); ver @@ -89,17 +87,31 @@ pub async fn update( }; if direct_download && !updatestack.is_empty() { - download_versions(current_list.clone(), config.clone(), updatestack, &mp, &list_p).await?; + download_versions( + current_list.clone(), + config.clone(), + updatestack, + &mp, + &list_p, + ) + .await?; //Disable old versions if !clean { - let d_p = mp.insert_before(&list_p, ProgressBar::new(current_versions.len().try_into().unwrap())); - d_p.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + let d_p = mp.insert_before( + &list_p, + ProgressBar::new(current_versions.len().try_into().unwrap()), + ); + d_p.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); for ver in current_versions { if delete_old { d_p.set_message(format!("Delete version {}", ver.0)); d_p.inc(1); - delete_version(current_list.clone(), ver.0)?; + delete_version(¤t_list, ver.0)?; } else if ver.0 != "NONE" { d_p.set_message(format!("Disable version {}", ver.0)); d_p.inc(1); @@ -125,9 +137,14 @@ pub async fn update( Ok(()) } -async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progress: &ProgressBar) -> MLE { - let applicable_versions = - versions(&config.apis.modrinth, String::from(id), list.clone()).await; +async fn specific_update( + config: &Cfg, + clean: bool, + list: List, + id: &str, + progress: &ProgressBar, +) -> MLE { + let applicable_versions = versions(&config.apis.modrinth, String::from(id), list.clone()).await; let mut versions: Vec = vec![]; @@ -142,15 +159,16 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre let mut current: Vec = vec![]; if clean || (versions.join("|") - != userlist_get_applicable_versions( - config, - String::from(&list.id), - String::from(id), - )?) + != userlist_get_applicable_versions(config, String::from(&list.id), String::from(id))?) { let current_str = extract_current_version(applicable_versions.clone())?; - if !clean { progress.println(format!("Found new version for {}", mods_get_info(config, id).unwrap().title)); } + if !clean { + progress.println(format!( + "Found new version for {}", + mods_get_info(config, id).unwrap().title + )); + } //get new versions let current_ver = match applicable_versions @@ -166,12 +184,19 @@ async fn specific_update(config: &Cfg, clean: bool, list: List, id: &str, progre let files = ¤t_ver.files; let link = match files.clone().into_iter().find(|f| f.primary) { - Some(f) => f, - None => { files[0].clone() } - } - .url; - - userlist_change_versions(config, list.id, current_str, versions.join("|"), link, id.to_string())?; + Some(f) => f, + None => files[0].clone(), + } + .url; + + userlist_change_versions( + config, + list.id, + current_str, + versions.join("|"), + link, + id.to_string(), + )?; } if current.is_empty() { diff --git a/src/config.rs b/src/config.rs index 54cf768..3858484 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,7 +7,7 @@ use std::{ use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; -use crate::{db::db_setup, error::MLE, Modloader, VersionLevel, check_game_versions}; +use crate::{check_game_versions, db::db_setup, error::MLE, Modloader, VersionLevel}; #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Cfg { @@ -72,7 +72,7 @@ impl Cfg { Err(..) => { create_versions_dummy(&versionfile).await?; check_game_versions(&versionfile, true).await?; - }, + } } Ok(config) @@ -95,7 +95,7 @@ fn create_config(path: &str) -> MLE<()> { versions: cache_dir, defaults: Defaults { modloader: Modloader::Fabric, - version: VersionLevel::Release + version: VersionLevel::Release, }, apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/"), diff --git a/src/db.rs b/src/db.rs index 1f3ad4c..f627ef4 100644 --- a/src/db.rs +++ b/src/db.rs @@ -120,9 +120,7 @@ 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); - +pub fn mods_remove(config: &Cfg, id: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -233,7 +231,10 @@ pub fn userlist_get_all_ids(config: &Cfg, list_id: &str) -> MLE> { } match mod_ids.is_empty() { - true => Err(MLError::new(ErrorType::DBError, &format!("NO_MODS_USERLIST{}", list_id))), + true => Err(MLError::new( + ErrorType::DBError, + &format!("NO_MODS_USERLIST{}", list_id), + )), false => Ok(mod_ids), } } @@ -325,10 +326,7 @@ 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, -) -> MLE> { +pub fn userlist_get_all_current_version_ids(config: &Cfg, list_id: String) -> MLE> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -342,10 +340,7 @@ pub fn userlist_get_all_current_version_ids( } if versions.is_empty() { - return Err(MLError::new( - ErrorType::DBError, - "NO_MODS_ON_LIST", - )); + return Err(MLError::new(ErrorType::DBError, "NO_MODS_ON_LIST")); }; Ok(versions) @@ -441,7 +436,11 @@ pub fn userlist_add_disabled_versions( 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 = format!("{}/data.db", config.data); let connection = Connection::open(data).unwrap(); @@ -504,19 +503,14 @@ pub fn lists_insert( connection.execute( "INSERT INTO lists VALUES (?1, ?2, ?3, ?4)", - [ - id, - mc_version, - &mod_loader.to_string(), - download_folder, - ], + [id, 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(()) } -pub fn lists_remove(config: &Cfg, id: String) -> MLE<()> { +pub fn lists_remove(config: &Cfg, id: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -593,7 +587,7 @@ pub fn lists_get_all_ids(config: &Cfg) -> MLE> { } //config -pub fn config_change_current_list(config: &Cfg, id: String) -> MLE<()> { +pub fn config_change_current_list(config: &Cfg, id: &str) -> MLE<()> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; @@ -655,7 +649,10 @@ pub fn s_config_create_version(config: &Cfg) -> Result<(), Box Result<(), Box> { +pub fn s_config_update_version( + config: &Cfg, + ver: String, +) -> Result<(), Box> { let data = format!("{}/data.db", config.data); let connection = Connection::open(data)?; diff --git a/src/error.rs b/src/error.rs index e6afeaa..f981f14 100644 --- a/src/error.rs +++ b/src/error.rs @@ -106,9 +106,11 @@ impl From for MLError { impl From for MLError { fn from(value: serde_json::error::Error) -> Self { - Self { etype: ErrorType::LibJson, message: value.to_string() } + Self { + etype: ErrorType::LibJson, + message: value.to_string(), + } } - } impl MLError { diff --git a/src/files.rs b/src/files.rs index 814f06d..e874d9d 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,12 +1,13 @@ use futures_util::StreamExt; -use indicatif::{ProgressBar, ProgressStyle, MultiProgress}; +use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; use reqwest::Client; -use tokio::task::JoinSet; use std::{ + cmp::min, collections::HashMap, fs::{copy, read_dir, remove_file, rename, File}, - io::Write, cmp::min, + io::Write, }; +use tokio::task::JoinSet; use crate::{ cache::{copy_cached_version, get_cached_versions}, @@ -14,34 +15,61 @@ use crate::{ db::{mods_get_info, userlist_add_disabled_versions}, error::{ErrorType, MLError, MLE}, modrinth::Version, - List, PROGRESS_CHARS, STYLE_SPINNER, STYLE_BAR_BYTE, STYLE_BAR_POS, + List, PROGRESS_CHARS, STYLE_BAR_BYTE, STYLE_BAR_POS, STYLE_SPINNER, }; -pub async fn download_versions(list: List, config: Cfg, versions: Vec, progress: &MultiProgress, progress_before: &ProgressBar) -> MLE<()> { +pub async fn download_versions( + list: List, + config: Cfg, + versions: Vec, + progress: &MultiProgress, + progress_before: &ProgressBar, +) -> MLE<()> { let cached = get_cached_versions(&config.cache); let mut js = JoinSet::new(); let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); - let all = progress.insert_before(progress_before, ProgressBar::new(versions.len().try_into().unwrap())); - all.set_style(ProgressStyle::with_template(STYLE_BAR_POS).unwrap().progress_chars(PROGRESS_CHARS)); + let all = progress.insert_before( + progress_before, + ProgressBar::new(versions.len().try_into().unwrap()), + ); + all.set_style( + ProgressStyle::with_template(STYLE_BAR_POS) + .unwrap() + .progress_chars(PROGRESS_CHARS), + ); all.set_message(format!("✓Downloading {}", list.id)); - + for ver in versions { let p = progress.insert_before(&all, ProgressBar::new(1)); p.set_style(style_spinner.clone()); - js.spawn(download_version(config.clone(), list.clone(), ver, cached.clone(), p)); + js.spawn(download_version( + config.clone(), + list.clone(), + ver, + cached.clone(), + p, + )); + } + + while js.join_next().await.is_some() { + all.inc(1) } - while js.join_next().await.is_some() { all.inc(1) } - all.finish_with_message(format!("✓Downloading {}", list.id)); Ok(()) } -async fn download_version(config: Cfg, list: List, version: Version, mut cached: HashMap, progress: ProgressBar) -> MLE<()> { +async fn download_version( + config: Cfg, + list: List, + version: Version, + mut cached: HashMap, + progress: ProgressBar, +) -> MLE<()> { let project_info = mods_get_info(&config, &version.project_id)?; let dl_path = String::from(&list.download_folder); @@ -59,7 +87,7 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: let files = version.files; let file = match files.clone().into_iter().find(|f| f.primary) { Some(f) => f, - None => files[0].clone() + None => files[0].clone(), }; let mut splitname: Vec<&str> = file.filename.split('.').collect(); let extension = match splitname.pop().ok_or("") { @@ -74,13 +102,7 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: extension ); - download_file( - &file.url, - &list.download_folder, - &filename, - &progress - ) - .await?; + download_file(&file.url, &list.download_folder, &filename, &progress).await?; progress.set_message(format!("Copy {} to cache", version.id)); let dl_path_file = format!("{}/{}", list.download_folder, filename); @@ -89,7 +111,10 @@ async fn download_version(config: Cfg, list: List, version: Version, mut cached: copy(dl_path_file, cache_path)?; } - progress.finish_with_message(format!("✓{} - {}{}", project_info.title, version.id, cache_msg)); + progress.finish_with_message(format!( + "✓{} - {}{}", + project_info.title, version.id, cache_msg + )); Ok(()) } @@ -117,7 +142,7 @@ async fn download_file(url: &str, path: &str, name: &str, progress: &ProgressBar // progress.inc(1); let chunk = item?; file.write_all(&chunk)?; - + // Progress bar let new = min(downloaded + (chunk.len() as u64), size); downloaded = new; @@ -136,7 +161,7 @@ pub fn disable_version( mod_id: String, ) -> MLE<()> { //println!("Disabling version {} for mod {}", versionid, mod_id); - let file = get_file_path(current_list.clone(), String::from(&versionid))?; + let file = get_file_path(¤t_list, String::from(&versionid))?; let disabled = format!("{}.disabled", file); rename(file, disabled)?; @@ -146,7 +171,7 @@ pub fn disable_version( Ok(()) } -pub fn delete_version(list: List, version: String) -> MLE<()> { +pub fn delete_version(list: &List, version: String) -> MLE<()> { let file = get_file_path(list, version)?; remove_file(file)?; @@ -154,9 +179,9 @@ pub fn delete_version(list: List, version: String) -> MLE<()> { Ok(()) } -pub fn get_file_path(list: List, versionid: String) -> MLE { +pub fn get_file_path(list: &List, versionid: String) -> MLE { let mut names: HashMap = HashMap::new(); - for file in read_dir(list.download_folder)? { + for file in read_dir(&list.download_folder)? { let path = file?.path(); if path.is_file() { let pathstr = match path.to_str().ok_or("") { diff --git a/src/lib.rs b/src/lib.rs index 7287660..8196f1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,20 +6,26 @@ pub mod db; pub mod error; pub mod files; -use std::{fmt::Display, fs::{File, remove_file, self}, io::{Write, Read}, time::Duration}; +use std::{ + fmt::Display, + fs::{self, remove_file, File}, + io::{Read, Write}, + time::Duration, +}; -pub use apis::*; use apis::modrinth::{get_game_versions, GameVersion, GameVersionType}; +pub use apis::*; pub use commands::*; use error::{ErrorType, MLError, MLE}; -use indicatif::{ProgressStyle, ProgressBar}; +use indicatif::{ProgressBar, ProgressStyle}; use serde::{Deserialize, Serialize}; -pub static STYLE_BAR_BYTE: &str = "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; +pub static STYLE_BAR_BYTE: &str = + "{spinner:.green}{wide_msg}{bytes}/{total_bytes} [{bar:.green/lime}]"; pub static STYLE_BAR_POS: &str = " {wide_msg}{pos}/{len} [{bar:.green/lime}]"; -pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; -pub static STYLE_OPERATION: &str = " {wide_msg}"; -pub static STYLE_MESSAGE: &str = "{wide_msg}"; +pub static STYLE_SPINNER: &str = "{spinner:.green}{wide_msg}"; +pub static STYLE_OPERATION: &str = " {wide_msg}"; +pub static STYLE_MESSAGE: &str = "{wide_msg}"; pub static PROGRESS_CHARS: &str = "#>-"; #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] @@ -59,7 +65,7 @@ pub enum VersionLevel { Release, #[serde(rename(serialize = "snapshot", deserialize = "snapshot"))] Snapshot, - Version(String) + Version(String), } /// Checks if update needed (time) @@ -70,7 +76,9 @@ pub async fn check_game_versions(path: &str, force: bool) -> MLE<()> { p.set_message("Update minecraft versions"); let creation_time = fs::metadata(path)?.created()?; - if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { return Ok(()); } + if !force && creation_time.elapsed().unwrap() < Duration::from_secs(60 * 60 * 24) { + return Ok(()); + } let versions = get_game_versions().await; remove_file(path)?; @@ -91,7 +99,6 @@ pub fn load_game_versions(path: &str) -> MLE> { } impl VersionLevel { - pub fn from(str: &str) -> Self { match str { "release" => VersionLevel::Release, @@ -107,22 +114,29 @@ impl VersionLevel { match self { VersionLevel::Release => { - let release = versions.find(|ver| ver.version_type == GameVersionType::release).unwrap(); + let release = versions + .find(|ver| ver.version_type == GameVersionType::release) + .unwrap(); println!("{:?}", release); Ok(release.version) - }, + } VersionLevel::Snapshot => { - let snapshot = versions.find(|ver| ver.version_type == GameVersionType::snapshot).unwrap(); + let snapshot = versions + .find(|ver| ver.version_type == GameVersionType::snapshot) + .unwrap(); println!("{:?}", snapshot); Ok(snapshot.version) - }, + } VersionLevel::Version(v) => { if versions.any(|ver| ver.version == v) { Ok(v) } else { - Err(MLError::new(ErrorType::ConfigError, "unknown minecraft version")) + Err(MLError::new( + ErrorType::ConfigError, + "unknown minecraft version", + )) } - }, + } } } } diff --git a/src/main.rs b/src/main.rs index d03f88a..d9ad6af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,8 @@ use clap::{Parser, Subcommand}; use modlist::{ config::Cfg, db::{config_get_current_list, lists_get, lists_get_all_ids}, - download, export, get_current_list, import, list_add, list_change, list_remove, list_version, - mod_add, mod_remove, update, IDSelector, List, Modloader, VersionLevel, list_list, AddMod, + download, export, get_current_list, import, list_add, list_change, list_list, list_remove, + list_version, mod_add, mod_remove, update, AddMod, IDSelector, List, Modloader, VersionLevel, }; #[derive(Parser)] @@ -43,7 +43,7 @@ enum Commands { /// remove disabled versions #[arg(short, long)] remove: bool, - + /// optional List selection, else default list will be used #[arg(short, long)] list: Option, @@ -81,7 +81,7 @@ enum Commands { /// the list you want to export list: Option, }, - Test + Test, } #[derive(Subcommand)] @@ -160,86 +160,87 @@ async fn main() { let config = Cfg::init(cli.config).await.unwrap(); match cli.command { - Commands::Mod { command } => { - match command { - ModCommands::Add { - id, - version, - list, - download, - lock, - } => { - let listf = match list { - Some(list) => lists_get(&config, &list).unwrap(), - None => lists_get( - &config, - &config_get_current_list(&config).unwrap(), - ) - .unwrap(), - }; + Commands::Mod { command } => match command { + ModCommands::Add { + id, + version, + list, + download, + lock, + } => { + let listf = match list { + Some(list) => lists_get(&config, &list).unwrap(), + None => lists_get(&config, &config_get_current_list(&config).unwrap()).unwrap(), + }; - let marked_id = match version { - true => IDSelector::VersionID(id), - false => IDSelector::ModificationID(id), - }; + let marked_id = match version { + true => IDSelector::VersionID(id), + false => IDSelector::ModificationID(id), + }; - let add_id = AddMod { id: marked_id, set_version: lock }; + let add_id = AddMod { + id: marked_id, + set_version: lock, + }; - mod_add(&config, vec![add_id], listf, download).await - } - ModCommands::Remove { id, list } => { - let listf = match list { - Some(list) => lists_get(&config, &list).unwrap(), - None => lists_get( - &config, - &config_get_current_list(&config).unwrap(), - ) - .unwrap(), - }; - mod_remove(&config, &id, listf) - } + mod_add(&config, vec![add_id], listf, download).await } - } - Commands::List { command, force_gameupdate } => { - match command { - ListCommands::Add { - id, - directory, - modloader, - version, - } => { - let ml = match modloader { - Some(ml) => Modloader::from(&ml).unwrap(), - None => config.defaults.modloader.clone(), - }; - - let versions_path = &config.versions; - let ver = match version { - Some(ver) => VersionLevel::from(&ver).get(versions_path, force_gameupdate).await.unwrap(), - None => config.defaults.version.clone().get(versions_path, force_gameupdate).await.unwrap(), - }; - - list_add(&config, &id, &ver, &ml, &directory) - } - ListCommands::Remove { id } => list_remove(&config, id), - ListCommands::List => { - list_list(&config) - } - ListCommands::Change { id } => list_change(&config, id), - ListCommands::Version { - id, - version, - download, - remove, - } => list_version(&config, &id, version, download, remove).await, + ModCommands::Remove { id, list } => { + let listf = match list { + Some(list) => lists_get(&config, &list).unwrap(), + None => lists_get(&config, &config_get_current_list(&config).unwrap()).unwrap(), + }; + mod_remove(&config, &id, &listf) } - } + }, + Commands::List { + command, + force_gameupdate, + } => match command { + ListCommands::Add { + id, + directory, + modloader, + version, + } => { + let ml = match modloader { + Some(ml) => Modloader::from(&ml).unwrap(), + None => config.defaults.modloader.clone(), + }; + + let versions_path = &config.versions; + let ver = match version { + Some(ver) => VersionLevel::from(&ver) + .get(versions_path, force_gameupdate) + .await + .unwrap(), + None => config + .defaults + .version + .clone() + .get(versions_path, force_gameupdate) + .await + .unwrap(), + }; + + list_add(&config, &id, &ver, &ml, &directory) + } + ListCommands::Remove { id } => list_remove(&config, &id), + ListCommands::List => list_list(&config), + ListCommands::Change { id } => list_change(&config, &id), + ListCommands::Version { + id, + version, + download, + remove, + } => list_version(&config, &id, version, download, remove).await, + }, Commands::Update { all, download, clean, remove, - list + list, } => { let mut liststack: Vec = vec![]; if all { @@ -248,7 +249,7 @@ async fn main() { liststack.push(lists_get(&config, &id).unwrap()); } } else { - let current = match list { + let current = match list { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; @@ -257,7 +258,12 @@ async fn main() { update(&config, liststack, clean, download, remove).await } - Commands::Download { all, clean, remove, list } => { + Commands::Download { + all, + clean, + remove, + list, + } => { let mut liststack: Vec = vec![]; if all { let list_ids = lists_get_all_ids(&config).unwrap(); @@ -265,15 +271,15 @@ async fn main() { liststack.push(lists_get(&config, &id).unwrap()); } } else { - let current = match list { + let current = match list { Some(l) => lists_get(&config, &l).unwrap(), None => get_current_list(&config).unwrap(), }; liststack.push(current) } - download(&config, liststack, clean, remove).await - }, + download(&config, liststack, clean, remove).await + } Commands::Import { file, download } => { let filestr: String = match file { Some(args) => args, -- cgit v1.2.3