summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-09-04 13:48:32 +0200
committerfxqnlr <[email protected]>2024-09-04 13:48:32 +0200
commit7a85cf311c85ab45c75098dae58b5ebf5fef60bc (patch)
tree8f65f35da12add062df7fdf6d63d47c664542261
parent638dc58e86ba3bbe31d50e72788c9681d414e0ae (diff)
downloadmodlist-7a85cf311c85ab45c75098dae58b5ebf5fef60bc.tar
modlist-7a85cf311c85ab45c75098dae58b5ebf5fef60bc.tar.gz
modlist-7a85cf311c85ab45c75098dae58b5ebf5fef60bc.zip
add config crate, slight cleanup
-rw-r--r--Cargo.lock376
-rw-r--r--Cargo.toml1
-rw-r--r--src/config.rs103
3 files changed, 411 insertions, 69 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 7960fdd..5b301ef 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -87,6 +87,17 @@ dependencies = [
87] 87]
88 88
89[[package]] 89[[package]]
90name = "async-trait"
91version = "0.1.82"
92source = "registry+https://github.com/rust-lang/crates.io-index"
93checksum = "a27b8a3a6e1a44fa4c8baf1f653e4172e81486d4941f2237e20dc2d0cf4ddff1"
94dependencies = [
95 "proc-macro2",
96 "quote",
97 "syn",
98]
99
100[[package]]
90name = "autocfg" 101name = "autocfg"
91version = "1.1.0" 102version = "1.1.0"
92source = "registry+https://github.com/rust-lang/crates.io-index" 103source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -124,6 +135,18 @@ name = "bitflags"
124version = "2.3.1" 135version = "2.3.1"
125source = "registry+https://github.com/rust-lang/crates.io-index" 136source = "registry+https://github.com/rust-lang/crates.io-index"
126checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84" 137checksum = "6776fc96284a0bb647b615056fc496d1fe1644a7ab01829818a6d91cae888b84"
138dependencies = [
139 "serde",
140]
141
142[[package]]
143name = "block-buffer"
144version = "0.10.4"
145source = "registry+https://github.com/rust-lang/crates.io-index"
146checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
147dependencies = [
148 "generic-array",
149]
127 150
128[[package]] 151[[package]]
129name = "bumpalo" 152name = "bumpalo"
@@ -222,6 +245,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
222checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" 245checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
223 246
224[[package]] 247[[package]]
248name = "config"
249version = "0.14.0"
250source = "registry+https://github.com/rust-lang/crates.io-index"
251checksum = "7328b20597b53c2454f0b1919720c25c7339051c02b72b7e05409e00b14132be"
252dependencies = [
253 "async-trait",
254 "convert_case",
255 "json5",
256 "lazy_static",
257 "nom",
258 "pathdiff",
259 "ron",
260 "rust-ini",
261 "serde",
262 "serde_json",
263 "toml 0.8.19",
264 "yaml-rust",
265]
266
267[[package]]
225name = "console" 268name = "console"
226version = "0.15.7" 269version = "0.15.7"
227source = "registry+https://github.com/rust-lang/crates.io-index" 270source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -235,6 +278,35 @@ dependencies = [
235] 278]
236 279
237[[package]] 280[[package]]
281name = "const-random"
282version = "0.1.18"
283source = "registry+https://github.com/rust-lang/crates.io-index"
284checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359"
285dependencies = [
286 "const-random-macro",
287]
288
289[[package]]
290name = "const-random-macro"
291version = "0.1.16"
292source = "registry+https://github.com/rust-lang/crates.io-index"
293checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e"
294dependencies = [
295 "getrandom",
296 "once_cell",
297 "tiny-keccak",
298]
299
300[[package]]
301name = "convert_case"
302version = "0.6.0"
303source = "registry+https://github.com/rust-lang/crates.io-index"
304checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
305dependencies = [
306 "unicode-segmentation",
307]
308
309[[package]]
238name = "core-foundation" 310name = "core-foundation"
239version = "0.9.3" 311version = "0.9.3"
240source = "registry+https://github.com/rust-lang/crates.io-index" 312source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -251,6 +323,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
251checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 323checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
252 324
253[[package]] 325[[package]]
326name = "cpufeatures"
327version = "0.2.9"
328source = "registry+https://github.com/rust-lang/crates.io-index"
329checksum = "a17b76ff3a4162b0b27f354a0c87015ddad39d35f9c0c36607a3bdd175dde1f1"
330dependencies = [
331 "libc",
332]
333
334[[package]]
335name = "crunchy"
336version = "0.2.2"
337source = "registry+https://github.com/rust-lang/crates.io-index"
338checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
339
340[[package]]
341name = "crypto-common"
342version = "0.1.6"
343source = "registry+https://github.com/rust-lang/crates.io-index"
344checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
345dependencies = [
346 "generic-array",
347 "typenum",
348]
349
350[[package]]
351name = "digest"
352version = "0.10.7"
353source = "registry+https://github.com/rust-lang/crates.io-index"
354checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
355dependencies = [
356 "block-buffer",
357 "crypto-common",
358]
359
360[[package]]
254name = "dirs" 361name = "dirs"
255version = "5.0.1" 362version = "5.0.1"
256source = "registry+https://github.com/rust-lang/crates.io-index" 363source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -272,6 +379,15 @@ dependencies = [
272] 379]
273 380
274[[package]] 381[[package]]
382name = "dlv-list"
383version = "0.5.2"
384source = "registry+https://github.com/rust-lang/crates.io-index"
385checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f"
386dependencies = [
387 "const-random",
388]
389
390[[package]]
275name = "encode_unicode" 391name = "encode_unicode"
276version = "0.3.6" 392version = "0.3.6"
277source = "registry+https://github.com/rust-lang/crates.io-index" 393source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -287,6 +403,12 @@ dependencies = [
287] 403]
288 404
289[[package]] 405[[package]]
406name = "equivalent"
407version = "1.0.1"
408source = "registry+https://github.com/rust-lang/crates.io-index"
409checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
410
411[[package]]
290name = "errno" 412name = "errno"
291version = "0.3.1" 413version = "0.3.1"
292source = "registry+https://github.com/rust-lang/crates.io-index" 414source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -430,6 +552,16 @@ dependencies = [
430] 552]
431 553
432[[package]] 554[[package]]
555name = "generic-array"
556version = "0.14.7"
557source = "registry+https://github.com/rust-lang/crates.io-index"
558checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
559dependencies = [
560 "typenum",
561 "version_check",
562]
563
564[[package]]
433name = "getrandom" 565name = "getrandom"
434version = "0.2.9" 566version = "0.2.9"
435source = "registry+https://github.com/rust-lang/crates.io-index" 567source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -458,7 +590,7 @@ dependencies = [
458 "futures-sink", 590 "futures-sink",
459 "futures-util", 591 "futures-util",
460 "http", 592 "http",
461 "indexmap", 593 "indexmap 1.9.3",
462 "slab", 594 "slab",
463 "tokio", 595 "tokio",
464 "tokio-util", 596 "tokio-util",
@@ -481,6 +613,12 @@ dependencies = [
481] 613]
482 614
483[[package]] 615[[package]]
616name = "hashbrown"
617version = "0.14.5"
618source = "registry+https://github.com/rust-lang/crates.io-index"
619checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
620
621[[package]]
484name = "hashlink" 622name = "hashlink"
485version = "0.8.2" 623version = "0.8.2"
486source = "registry+https://github.com/rust-lang/crates.io-index" 624source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -625,6 +763,16 @@ dependencies = [
625] 763]
626 764
627[[package]] 765[[package]]
766name = "indexmap"
767version = "2.5.0"
768source = "registry+https://github.com/rust-lang/crates.io-index"
769checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5"
770dependencies = [
771 "equivalent",
772 "hashbrown 0.14.5",
773]
774
775[[package]]
628name = "indicatif" 776name = "indicatif"
629version = "0.17.3" 777version = "0.17.3"
630source = "registry+https://github.com/rust-lang/crates.io-index" 778source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -690,6 +838,17 @@ dependencies = [
690] 838]
691 839
692[[package]] 840[[package]]
841name = "json5"
842version = "0.4.1"
843source = "registry+https://github.com/rust-lang/crates.io-index"
844checksum = "96b0db21af676c1ce64250b5f40f3ce2cf27e4e47cb91ed91eb6fe9350b430c1"
845dependencies = [
846 "pest",
847 "pest_derive",
848 "serde",
849]
850
851[[package]]
693name = "lazy_static" 852name = "lazy_static"
694version = "1.4.0" 853version = "1.4.0"
695source = "registry+https://github.com/rust-lang/crates.io-index" 854source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -713,6 +872,12 @@ dependencies = [
713] 872]
714 873
715[[package]] 874[[package]]
875name = "linked-hash-map"
876version = "0.5.6"
877source = "registry+https://github.com/rust-lang/crates.io-index"
878checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
879
880[[package]]
716name = "linux-raw-sys" 881name = "linux-raw-sys"
717version = "0.3.8" 882version = "0.3.8"
718source = "registry+https://github.com/rust-lang/crates.io-index" 883source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -750,6 +915,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
750checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" 915checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
751 916
752[[package]] 917[[package]]
918name = "minimal-lexical"
919version = "0.2.1"
920source = "registry+https://github.com/rust-lang/crates.io-index"
921checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
922
923[[package]]
753name = "miniz_oxide" 924name = "miniz_oxide"
754version = "0.6.2" 925version = "0.6.2"
755source = "registry+https://github.com/rust-lang/crates.io-index" 926source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -777,6 +948,7 @@ dependencies = [
777 "chrono", 948 "chrono",
778 "clap", 949 "clap",
779 "clap_complete", 950 "clap_complete",
951 "config",
780 "dirs", 952 "dirs",
781 "error-chain", 953 "error-chain",
782 "futures-util", 954 "futures-util",
@@ -786,7 +958,7 @@ dependencies = [
786 "serde", 958 "serde",
787 "serde_json", 959 "serde_json",
788 "tokio", 960 "tokio",
789 "toml", 961 "toml 0.7.4",
790] 962]
791 963
792[[package]] 964[[package]]
@@ -808,6 +980,16 @@ dependencies = [
808] 980]
809 981
810[[package]] 982[[package]]
983name = "nom"
984version = "7.1.3"
985source = "registry+https://github.com/rust-lang/crates.io-index"
986checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
987dependencies = [
988 "memchr",
989 "minimal-lexical",
990]
991
992[[package]]
811name = "num-integer" 993name = "num-integer"
812version = "0.1.45" 994version = "0.1.45"
813source = "registry+https://github.com/rust-lang/crates.io-index" 995source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -908,6 +1090,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
908checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" 1090checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
909 1091
910[[package]] 1092[[package]]
1093name = "ordered-multimap"
1094version = "0.6.0"
1095source = "registry+https://github.com/rust-lang/crates.io-index"
1096checksum = "4ed8acf08e98e744e5384c8bc63ceb0364e68a6854187221c18df61c4797690e"
1097dependencies = [
1098 "dlv-list",
1099 "hashbrown 0.13.2",
1100]
1101
1102[[package]]
911name = "parking_lot" 1103name = "parking_lot"
912version = "0.12.1" 1104version = "0.12.1"
913source = "registry+https://github.com/rust-lang/crates.io-index" 1105source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -931,12 +1123,63 @@ dependencies = [
931] 1123]
932 1124
933[[package]] 1125[[package]]
1126name = "pathdiff"
1127version = "0.2.1"
1128source = "registry+https://github.com/rust-lang/crates.io-index"
1129checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
1130
1131[[package]]
934name = "percent-encoding" 1132name = "percent-encoding"
935version = "2.2.0" 1133version = "2.2.0"
936source = "registry+https://github.com/rust-lang/crates.io-index" 1134source = "registry+https://github.com/rust-lang/crates.io-index"
937checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" 1135checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e"
938 1136
939[[package]] 1137[[package]]
1138name = "pest"
1139version = "2.7.11"
1140source = "registry+https://github.com/rust-lang/crates.io-index"
1141checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95"
1142dependencies = [
1143 "memchr",
1144 "thiserror",
1145 "ucd-trie",
1146]
1147
1148[[package]]
1149name = "pest_derive"
1150version = "2.7.11"
1151source = "registry+https://github.com/rust-lang/crates.io-index"
1152checksum = "2a548d2beca6773b1c244554d36fcf8548a8a58e74156968211567250e48e49a"
1153dependencies = [
1154 "pest",
1155 "pest_generator",
1156]
1157
1158[[package]]
1159name = "pest_generator"
1160version = "2.7.11"
1161source = "registry+https://github.com/rust-lang/crates.io-index"
1162checksum = "3c93a82e8d145725dcbaf44e5ea887c8a869efdcc28706df2d08c69e17077183"
1163dependencies = [
1164 "pest",
1165 "pest_meta",
1166 "proc-macro2",
1167 "quote",
1168 "syn",
1169]
1170
1171[[package]]
1172name = "pest_meta"
1173version = "2.7.11"
1174source = "registry+https://github.com/rust-lang/crates.io-index"
1175checksum = "a941429fea7e08bedec25e4f6785b6ffaacc6b755da98df5ef3e7dcf4a124c4f"
1176dependencies = [
1177 "once_cell",
1178 "pest",
1179 "sha2",
1180]
1181
1182[[package]]
940name = "pin-project-lite" 1183name = "pin-project-lite"
941version = "0.2.9" 1184version = "0.2.9"
942source = "registry+https://github.com/rust-lang/crates.io-index" 1185source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -971,18 +1214,18 @@ checksum = "dc59d1bcc64fc5d021d67521f818db868368028108d37f0e98d74e33f68297b5"
971 1214
972[[package]] 1215[[package]]
973name = "proc-macro2" 1216name = "proc-macro2"
974version = "1.0.59" 1217version = "1.0.86"
975source = "registry+https://github.com/rust-lang/crates.io-index" 1218source = "registry+https://github.com/rust-lang/crates.io-index"
976checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" 1219checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77"
977dependencies = [ 1220dependencies = [
978 "unicode-ident", 1221 "unicode-ident",
979] 1222]
980 1223
981[[package]] 1224[[package]]
982name = "quote" 1225name = "quote"
983version = "1.0.28" 1226version = "1.0.37"
984source = "registry+https://github.com/rust-lang/crates.io-index" 1227source = "registry+https://github.com/rust-lang/crates.io-index"
985checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" 1228checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
986dependencies = [ 1229dependencies = [
987 "proc-macro2", 1230 "proc-macro2",
988] 1231]
@@ -1056,6 +1299,18 @@ dependencies = [
1056] 1299]
1057 1300
1058[[package]] 1301[[package]]
1302name = "ron"
1303version = "0.8.1"
1304source = "registry+https://github.com/rust-lang/crates.io-index"
1305checksum = "b91f7eff05f748767f183df4320a63d6936e9c6107d97c9e6bdd9784f4289c94"
1306dependencies = [
1307 "base64",
1308 "bitflags 2.3.1",
1309 "serde",
1310 "serde_derive",
1311]
1312
1313[[package]]
1059name = "rusqlite" 1314name = "rusqlite"
1060version = "0.29.0" 1315version = "0.29.0"
1061source = "registry+https://github.com/rust-lang/crates.io-index" 1316source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1070,6 +1325,16 @@ dependencies = [
1070] 1325]
1071 1326
1072[[package]] 1327[[package]]
1328name = "rust-ini"
1329version = "0.19.0"
1330source = "registry+https://github.com/rust-lang/crates.io-index"
1331checksum = "7e2a3bcec1f113553ef1c88aae6c020a369d03d55b58de9869a0908930385091"
1332dependencies = [
1333 "cfg-if",
1334 "ordered-multimap",
1335]
1336
1337[[package]]
1073name = "rustc-demangle" 1338name = "rustc-demangle"
1074version = "0.1.23" 1339version = "0.1.23"
1075source = "registry+https://github.com/rust-lang/crates.io-index" 1340source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1166,9 +1431,9 @@ dependencies = [
1166 1431
1167[[package]] 1432[[package]]
1168name = "serde_spanned" 1433name = "serde_spanned"
1169version = "0.6.2" 1434version = "0.6.7"
1170source = "registry+https://github.com/rust-lang/crates.io-index" 1435source = "registry+https://github.com/rust-lang/crates.io-index"
1171checksum = "93107647184f6027e3b7dcb2e11034cf95ffa1e3a682c67951963ac69c1c007d" 1436checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d"
1172dependencies = [ 1437dependencies = [
1173 "serde", 1438 "serde",
1174] 1439]
@@ -1186,6 +1451,17 @@ dependencies = [
1186] 1451]
1187 1452
1188[[package]] 1453[[package]]
1454name = "sha2"
1455version = "0.10.8"
1456source = "registry+https://github.com/rust-lang/crates.io-index"
1457checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8"
1458dependencies = [
1459 "cfg-if",
1460 "cpufeatures",
1461 "digest",
1462]
1463
1464[[package]]
1189name = "signal-hook-registry" 1465name = "signal-hook-registry"
1190version = "1.4.1" 1466version = "1.4.1"
1191source = "registry+https://github.com/rust-lang/crates.io-index" 1467source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1227,9 +1503,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
1227 1503
1228[[package]] 1504[[package]]
1229name = "syn" 1505name = "syn"
1230version = "2.0.17" 1506version = "2.0.77"
1231source = "registry+https://github.com/rust-lang/crates.io-index" 1507source = "registry+https://github.com/rust-lang/crates.io-index"
1232checksum = "45b6ddbb36c5b969c182aec3c4a0bce7df3fbad4b77114706a49aacc80567388" 1508checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed"
1233dependencies = [ 1509dependencies = [
1234 "proc-macro2", 1510 "proc-macro2",
1235 "quote", 1511 "quote",
@@ -1281,6 +1557,15 @@ dependencies = [
1281] 1557]
1282 1558
1283[[package]] 1559[[package]]
1560name = "tiny-keccak"
1561version = "2.0.2"
1562source = "registry+https://github.com/rust-lang/crates.io-index"
1563checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237"
1564dependencies = [
1565 "crunchy",
1566]
1567
1568[[package]]
1284name = "tinyvec" 1569name = "tinyvec"
1285version = "1.6.0" 1570version = "1.6.0"
1286source = "registry+https://github.com/rust-lang/crates.io-index" 1571source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1358,14 +1643,26 @@ dependencies = [
1358 "serde", 1643 "serde",
1359 "serde_spanned", 1644 "serde_spanned",
1360 "toml_datetime", 1645 "toml_datetime",
1361 "toml_edit", 1646 "toml_edit 0.19.10",
1647]
1648
1649[[package]]
1650name = "toml"
1651version = "0.8.19"
1652source = "registry+https://github.com/rust-lang/crates.io-index"
1653checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e"
1654dependencies = [
1655 "serde",
1656 "serde_spanned",
1657 "toml_datetime",
1658 "toml_edit 0.22.20",
1362] 1659]
1363 1660
1364[[package]] 1661[[package]]
1365name = "toml_datetime" 1662name = "toml_datetime"
1366version = "0.6.2" 1663version = "0.6.8"
1367source = "registry+https://github.com/rust-lang/crates.io-index" 1664source = "registry+https://github.com/rust-lang/crates.io-index"
1368checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" 1665checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41"
1369dependencies = [ 1666dependencies = [
1370 "serde", 1667 "serde",
1371] 1668]
@@ -1376,11 +1673,24 @@ version = "0.19.10"
1376source = "registry+https://github.com/rust-lang/crates.io-index" 1673source = "registry+https://github.com/rust-lang/crates.io-index"
1377checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739" 1674checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739"
1378dependencies = [ 1675dependencies = [
1379 "indexmap", 1676 "indexmap 1.9.3",
1380 "serde", 1677 "serde",
1381 "serde_spanned", 1678 "serde_spanned",
1382 "toml_datetime", 1679 "toml_datetime",
1383 "winnow", 1680 "winnow 0.4.6",
1681]
1682
1683[[package]]
1684name = "toml_edit"
1685version = "0.22.20"
1686source = "registry+https://github.com/rust-lang/crates.io-index"
1687checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d"
1688dependencies = [
1689 "indexmap 2.5.0",
1690 "serde",
1691 "serde_spanned",
1692 "toml_datetime",
1693 "winnow 0.6.18",
1384] 1694]
1385 1695
1386[[package]] 1696[[package]]
@@ -1416,6 +1726,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1416checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" 1726checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
1417 1727
1418[[package]] 1728[[package]]
1729name = "typenum"
1730version = "1.17.0"
1731source = "registry+https://github.com/rust-lang/crates.io-index"
1732checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
1733
1734[[package]]
1735name = "ucd-trie"
1736version = "0.1.6"
1737source = "registry+https://github.com/rust-lang/crates.io-index"
1738checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9"
1739
1740[[package]]
1419name = "unicode-bidi" 1741name = "unicode-bidi"
1420version = "0.3.13" 1742version = "0.3.13"
1421source = "registry+https://github.com/rust-lang/crates.io-index" 1743source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1437,6 +1759,12 @@ dependencies = [
1437] 1759]
1438 1760
1439[[package]] 1761[[package]]
1762name = "unicode-segmentation"
1763version = "1.11.0"
1764source = "registry+https://github.com/rust-lang/crates.io-index"
1765checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
1766
1767[[package]]
1440name = "unicode-width" 1768name = "unicode-width"
1441version = "0.1.10" 1769version = "0.1.10"
1442source = "registry+https://github.com/rust-lang/crates.io-index" 1770source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1770,6 +2098,15 @@ dependencies = [
1770] 2098]
1771 2099
1772[[package]] 2100[[package]]
2101name = "winnow"
2102version = "0.6.18"
2103source = "registry+https://github.com/rust-lang/crates.io-index"
2104checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f"
2105dependencies = [
2106 "memchr",
2107]
2108
2109[[package]]
1773name = "winreg" 2110name = "winreg"
1774version = "0.10.1" 2111version = "0.10.1"
1775source = "registry+https://github.com/rust-lang/crates.io-index" 2112source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1777,3 +2114,12 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
1777dependencies = [ 2114dependencies = [
1778 "winapi", 2115 "winapi",
1779] 2116]
2117
2118[[package]]
2119name = "yaml-rust"
2120version = "0.4.5"
2121source = "registry+https://github.com/rust-lang/crates.io-index"
2122checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
2123dependencies = [
2124 "linked-hash-map",
2125]
diff --git a/Cargo.toml b/Cargo.toml
index 35f65f4..39e73c8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,3 +19,4 @@ dirs = "5.0.0"
19clap = { version = "4.2.1", features = ["derive"] } 19clap = { version = "4.2.1", features = ["derive"] }
20clap_complete = "4.2.0" 20clap_complete = "4.2.0"
21indicatif = "0.17.3" 21indicatif = "0.17.3"
22config = "0.14.0"
diff --git a/src/config.rs b/src/config.rs
index 6280932..8ecdc69 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,14 +1,16 @@
1use std::{ 1use std::{
2 fs::{create_dir_all, File}, 2 fs::{create_dir_all, File},
3 io::{Read, Write}, 3 io::Write,
4 path::Path, 4 path::Path,
5}; 5};
6 6
7use indicatif::{ProgressBar, ProgressStyle};
8use serde::{Deserialize, Serialize}; 7use serde::{Deserialize, Serialize};
9 8
10use crate::{ 9use crate::{
11 check_game_versions, db::setup, error::{EType, MLErr, MLE}, Modloader, VersionLevel, 10 check_game_versions,
11 db::setup,
12 error::{EType, MLErr, MLE},
13 Modloader, VersionLevel,
12}; 14};
13 15
14#[derive(Debug, Clone, Serialize, Deserialize)] 16#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -20,6 +22,28 @@ pub struct Cfg {
20 pub apis: Apis, 22 pub apis: Apis,
21} 23}
22 24
25impl Default for Cfg {
26 fn default() -> Self {
27 let cache_dir = dirs::cache_dir()
28 .unwrap()
29 .join("modlist")
30 .to_string_lossy()
31 .to_string();
32 Self {
33 data: cache_dir.clone(),
34 cache: format!("{cache_dir}/cache"),
35 versions: cache_dir,
36 defaults: Defaults {
37 modloader: Modloader::Fabric,
38 version: VersionLevel::Release,
39 },
40 apis: Apis {
41 modrinth: String::from("https://api.modrinth.com/v2/"),
42 },
43 }
44 }
45}
46
23#[derive(Debug, Clone, Serialize, Deserialize)] 47#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct Apis { 48pub struct Apis {
25 pub modrinth: String, 49 pub modrinth: String,
@@ -44,21 +68,24 @@ impl Cfg {
44 .to_string(), 68 .to_string(),
45 }; 69 };
46 70
47 let mut file = match File::open(&configfile) { 71 if let Some(err) = File::open(&configfile).err() {
48 Ok(file) => file, 72 if err.kind() == std::io::ErrorKind::NotFound && path.is_none() {
49 Err(err) => { 73 create_config(&configfile)?;
50 if err.kind() == std::io::ErrorKind::NotFound && path.is_none() 74 } else {
51 { 75 return Err(err.into());
52 create_config(&configfile)?; 76 };
53 File::open(&configfile)?
54 } else {
55 return Err(err.into());
56 }
57 }
58 }; 77 };
59 let mut content = String::new(); 78
60 file.read_to_string(&mut content)?; 79 let config: Cfg = config::Config::builder()
61 let config = toml::from_str::<Cfg>(&content)?; 80 .add_source(config::File::with_name(&configfile).required(false))
81 .add_source(
82 config::Environment::with_prefix("MODLIST").separator("_"),
83 )
84 .build()
85 .unwrap()
86 .try_deserialize()
87 .unwrap();
88
62 //Check cache 89 //Check cache
63 if !Path::new(&config.cache).exists() { 90 if !Path::new(&config.cache).exists() {
64 create_cache(&config.cache)?; 91 create_cache(&config.cache)?;
@@ -81,60 +108,28 @@ impl Cfg {
81} 108}
82 109
83fn create_config(path: &str) -> MLE<()> { 110fn create_config(path: &str) -> MLE<()> {
84 let p = ProgressBar::new(1);
85 p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap());
86 p.set_message("Create default config");
87
88 let cache_dir = dirs::cache_dir()
89 .unwrap()
90 .join("modlist")
91 .to_string_lossy()
92 .to_string();
93 let default_cfg = Cfg {
94 data: cache_dir.clone(),
95 cache: format!("{cache_dir}/cache"),
96 versions: cache_dir,
97 defaults: Defaults {
98 modloader: Modloader::Fabric,
99 version: VersionLevel::Release,
100 },
101 apis: Apis {
102 modrinth: String::from("https://api.modrinth.com/v2/"),
103 },
104 };
105 create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?; 111 create_dir_all(path.split("config.toml").collect::<Vec<&str>>()[0])?;
106 let mut file = File::create(path)?; 112 let mut file = File::create(path)?;
107 file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; 113 file.write_all(toml::to_string(&Cfg::default())?.as_bytes())?;
108 p.finish_with_message(format!("Created default config ({path})")); 114 println!("Created default config ({path})");
109 Ok(()) 115 Ok(())
110} 116}
111 117
112fn create_database(path: &str) -> MLE<()> { 118fn create_database(path: &str) -> MLE<()> {
113 let p = ProgressBar::new(1);
114 p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap());
115 p.set_message("Create database");
116
117 File::create(path)?; 119 File::create(path)?;
118 setup(path)?; 120 setup(path)?;
119 p.finish_with_message(format!("Created database ({path})")); 121 println!("Created database ({path})");
120 Ok(()) 122 Ok(())
121} 123}
122 124
123fn create_cache(path: &str) -> MLE<()> { 125fn create_cache(path: &str) -> MLE<()> {
124 let p = ProgressBar::new(1);
125 p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap());
126 p.set_message("Create cache");
127
128 create_dir_all(path)?; 126 create_dir_all(path)?;
129 p.finish_with_message(format!("Created cache ({path})")); 127 println!("Created cache ({path})");
130 Ok(()) 128 Ok(())
131} 129}
132 130
133fn create_versions_dummy(path: &str) -> MLE<()> { 131fn create_versions_dummy(path: &str) -> MLE<()> {
134 let p = ProgressBar::new(1);
135 p.set_style(ProgressStyle::with_template("{wide_msg}").unwrap());
136 p.set_message("Create version file");
137 File::create(path)?; 132 File::create(path)?;
138 p.finish_with_message(format!("Created version file ({path})")); 133 println!("Created version file ({path})");
139 Ok(()) 134 Ok(())
140} 135}