diff options
Diffstat (limited to 'mingling_cli')
25 files changed, 1935 insertions, 219 deletions
diff --git a/mingling_cli/.gitignore b/mingling_cli/.gitignore index 6a6d575..8b13789 100644 --- a/mingling_cli/.gitignore +++ b/mingling_cli/.gitignore @@ -1 +1 @@ -registry.json + diff --git a/mingling_cli/Cargo.lock b/mingling_cli/Cargo.lock index a5976a9..c738a0e 100644 --- a/mingling_cli/Cargo.lock +++ b/mingling_cli/Cargo.lock @@ -3,6 +3,12 @@ version = 4 [[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] name = "annotate-snippets" version = "0.12.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -37,6 +43,30 @@ dependencies = [ ] [[package]] +name = "async-compression" +version = "0.4.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3976abdc8fe7d1133d43d304afd42abdf5bc3e1319d263d223bde07b5efc4be8" +dependencies = [ + "compression-codecs", + "compression-core", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] name = "bitflags" version = "2.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -52,6 +82,12 @@ dependencies = [ ] [[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] name = "bytes" version = "1.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -92,21 +128,65 @@ dependencies = [ ] [[package]] +name = "cc" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509591b7bcd67f4ef775afad7662703b4935daaa6ec0e5605cfb1090b32a2b6d" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core", +] + +[[package]] name = "colored" version = "3.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" dependencies = [ - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "compression-codecs" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce2548391e9c1929c21bf6aa2680af86fe4c1b33e6cea9ac1cfeec0bd11218cf" +dependencies = [ + "compression-core", + "flate2", + "memchr", ] [[package]] +name = "compression-core" +version = "0.4.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc14f565cf027a105f7a44ccf9e5b424348421a1d8952a8fc9d499d313107789" + +[[package]] name = "cpufeatures" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -116,6 +196,24 @@ dependencies = [ ] [[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9481c1c90cbf2ac953f07c8d4a58aa3945c425b7185c9154d67a65e4230da511" +dependencies = [ + "cfg-if", +] + +[[package]] name = "crypto-common" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -219,7 +317,18 @@ dependencies = [ "libc", "option-ext", "redox_users", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.2", ] [[package]] @@ -235,7 +344,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "filetime" +version = "0.2.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c287a33c7f0a620c38e641e7f60827713987b3c0f26e8ddc9462cc69cf75759" +dependencies = [ + "cfg-if", + "libc", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d45db016d36b838f563236e9193d0ee6ce38f3f68b6c94e914b4929c96bbb890" + +[[package]] +name = "flate2" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843fba2746e448b37e26a819579957415c8cef339bf08564fe8b7ddbd959573c" +dependencies = [ + "crc32fast", + "miniz_oxide", ] [[package]] @@ -245,6 +380,54 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] name = "generic-array" version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -261,8 +444,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "r-efi", + "rand_core", + "wasm-bindgen", ] [[package]] @@ -272,12 +471,214 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" [[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d22053281f852e11534f5198498373cbb59295120a20771d90f7ed1897490a72" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ca68d021ef39cf6463ab54c1d0f5daf03377b70561305bb89a8f83aab66e0f" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa68d21081c4a05d5a901a1c62add574c77048b6a1c67be3b50ce0b60d4ca513" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d56e28588da92eee5c3201a6eff33fabdd49b62269c8938d4ff050ce4d900deb" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f9cf5f235641ed274641dd81c3f28d870e276763d0797aeeab72317b1c646f" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1563da1ed3e0b3bf3d74c9b85917ac9c56464d2f57242270c09c9e752f8021a0" + +[[package]] +name = "icu_properties" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7ca276ad3145661a65914e6daf131ca5120cd3dcee8f8f3214b8875184a148" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e590f038c1464a96894fd6d10127e90a8be4509f56ff7ecef851b15cee0b7caa" + +[[package]] +name = "icu_provider" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92a7ed671a6aad807a8651a2e1782a6598fda9ce5185dd8158549e95a91c6428" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] name = "indexmap" version = "2.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -288,12 +689,29 @@ dependencies = [ ] [[package]] +name = "ipnet" +version = "2.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a756c3fac73139e83f14c2d742155dd2b78d3ee56597b419a0579b7bdd6dd78" + +[[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] +name = "js-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0c1080212aad755ea003d18543e8768dd432c48819efd73a7bf1e39b7a5a3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] name = "just_fmt" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -342,6 +760,18 @@ dependencies = [ ] [[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] name = "lock_api" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -351,6 +781,18 @@ dependencies = [ ] [[package]] +name = "log" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad" + +[[package]] +name = "lru-slab" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "112b39cec0b298b6c1999fee3e31427f74f676e4cb9879ed1a121b43661a4154" + +[[package]] name = "memchr" version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -370,7 +812,7 @@ dependencies = [ [[package]] name = "mingling" -version = "0.4.0" +version = "0.5.0" dependencies = [ "arg-picker", "mingling_core", @@ -379,29 +821,32 @@ dependencies = [ [[package]] name = "mingling-cli" -version = "0.4.0" +version = "0.5.0" dependencies = [ "annotate-snippets", "cargo_metadata", "colored", "dirs", + "flate2", "just_fmt 0.2.0", "just_template", "mingling", "proc-macro2", "quote", + "reqwest", "semver", "serde", "serde_json", "sha2", "syn 3.0.2", + "tar", "tokio", "toml_edit 0.25.13+spec-1.1.0", ] [[package]] name = "mingling_core" -version = "0.4.0" +version = "0.5.0" dependencies = [ "just_fmt 0.2.0", "just_template", @@ -411,7 +856,7 @@ dependencies = [ [[package]] name = "mingling_macros" -version = "0.4.0" +version = "0.5.0" dependencies = [ "just_fmt 0.2.0", "proc-macro2", @@ -421,7 +866,7 @@ dependencies = [ [[package]] name = "mingling_pathf" -version = "0.4.0" +version = "0.5.0" dependencies = [ "just_fmt 0.2.0", "proc-macro2", @@ -429,6 +874,16 @@ dependencies = [ ] [[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] name = "mio" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -436,10 +891,16 @@ checksum = "30d65c71f1ce40ab09135ce117d742b9f8a19ff91a41a8b57ed50bc2de59c427" dependencies = [ "libc", "wasi", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] name = "option-ext" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -469,12 +930,27 @@ dependencies = [ ] [[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] name = "pin-project-lite" version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" [[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] name = "proc-macro2" version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -484,6 +960,62 @@ dependencies = [ ] [[package]] +name = "quinn" +version = "0.11.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c1a41e437b6bbd489372cd4971de128e85c855f56c57f283d20ff016cf7c0a8" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + +[[package]] name = "quote" version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -493,6 +1025,38 @@ dependencies = [ ] [[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core", +] + +[[package]] name = "redox_syscall" version = "0.5.18" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -507,12 +1071,130 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" dependencies = [ - "getrandom", + "getrandom 0.2.17", "libredox", "thiserror", ] [[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0283386ce02abc0151e1761d08802dfe86c173b0b494af5cbc086574e453da06" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f4925028c7eb5d1fcdaf196971378ed9d2c1c4efc7dc5d011256f76c99c0a96" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0527518605e68109d875e248ea259b6758801cf165e4b2c2733ae3b51f12535a" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -581,17 +1263,35 @@ dependencies = [ ] [[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] name = "sha2" version = "0.10.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] [[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] name = "signal-hook-registry" version = "1.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -602,6 +1302,18 @@ dependencies = [ ] [[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] name = "smallvec" version = "1.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -614,16 +1326,28 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] name = "syn" version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -646,6 +1370,37 @@ dependencies = [ ] [[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tar" +version = "0.4.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f6221d9a6003c78398e3b239969f352578258df48c8eb051caadae0015bc840" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] name = "thiserror" version = "2.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -666,6 +1421,31 @@ dependencies = [ ] [[package]] +name = "tinystr" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1e27c91459209c2986af3dcf603a5a74a4368754ce37414f59acc971167f643" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb4ebadaa0af04fab11ae01eb5f9fdb5f9c5b875506e210e71c07873528baa7f" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] name = "tokio" version = "1.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -679,7 +1459,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -694,6 +1474,29 @@ dependencies = [ ] [[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "494815d09bf52b5548659851081238f0ca39ff638363907596da739561c62c52" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] name = "toml" version = "0.8.23" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -772,6 +1575,81 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" [[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "async-compression", + "bitflags", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "pin-project-lite", + "tokio", + "tokio-util", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] name = "typenum" version = "1.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -790,18 +1668,135 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4ac048d71ede7ee76d585517add45da530660ef4390e49b098733c6e897f254" [[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" [[package]] +name = "wasm-bindgen" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b70935747edd64d89de3efa29d73789b806c15798f8e7dca4d8ac356b50ce70" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b7777d5cc23d0e91404e53ce2d5e8ec7acae3026b16233dba62cd3246457950" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77775f8f3f7217702089053b94958f8f54061a3f663417df76e19cbdcca29bc1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e11d33f857dc2fb11b8bc75aee111aa9cbeb12cd9f25efd3d4c2a3dd4e235284" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 2.0.119", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.127" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef64dbcc55df09c7e5a46182d181c2cfa3e925f3da937ea764728b4bbb9dcbf" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "web-sys" +version = "0.3.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c435338968042f4f59a557f690a253676d47ce13ceb55d70100e7facf6620a30" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcd9d09a39985f5344844e66b0c530a33843579125f23e21e9f0f220850f22a" +dependencies = [ + "rustls-pki-types", +] + +[[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -809,6 +1804,15 @@ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" @@ -817,6 +1821,70 @@ dependencies = [ ] [[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] name = "winnow" version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -835,6 +1903,105 @@ dependencies = [ ] [[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "xattr" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e45ad4206f6d2479085147f02bc2ef834ac85886624a23575ae137c8aa8156" +dependencies = [ + "libc", + "rustix", +] + +[[package]] +name = "yoke" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "709fe23a0424b6a435d82152b1bd3fdfb0833487d5fa90d05d42762a9891fef5" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13c156562582aa81c60cb29407084cdb54c4164760106ab78e6c5b0858cf64e" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94b5c6b5976d66c1d703c4fd17d3f5e43c8cedaacf604961b171adc7130896d8" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47402523226a02bfe5230160dc3ccc089aa6f6f19e7fcbb4e6f824bbb1b4aa62" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.2", +] + +[[package]] name = "zmij" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/mingling_cli/Cargo.toml b/mingling_cli/Cargo.toml index 5f9778a..dfc686d 100644 --- a/mingling_cli/Cargo.toml +++ b/mingling_cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mingling-cli" -version = "0.4.0" +version = "0.5.0" edition = "2024" license = "MIT OR Apache-2.0" repository = "https://github.com/mingling-rs/mingling/tree/main/mingling_cli" @@ -68,6 +68,11 @@ just_template = "0.2.1" # Template sources sha2 = "0.10" +# Self-update +reqwest = { version = "0.12", default-features = false, features = ["rustls-tls", "gzip"] } +tar = "0.4" +flate2 = "1" + [build-dependencies] # Configure & Serialization serde = { version = "1.0.229", features = ["derive"] } diff --git a/mingling_cli/help/help.txt b/mingling_cli/help/help.txt index 04bb972..2f2e14b 100644 --- a/mingling_cli/help/help.txt +++ b/mingling_cli/help/help.txt @@ -36,3 +36,6 @@ __ cfg <KEY> <VALUE> *Edit the value of a configuration item* __ cfg <KEY> *Print the value of the configuration item; print nothing if it does not exist* __ cfg <KEY> --pair *Output in the form of `"key" = "value"`* __ cfg *Print all configuration items, can be used with grep for searching* + +__ **MINGLING:** +__ update *Update mling to the latest version* diff --git a/mingling_cli/pre/lint_registry.rs b/mingling_cli/pre/lint_registry.rs index e69592b..5bfd3fe 100644 --- a/mingling_cli/pre/lint_registry.rs +++ b/mingling_cli/pre/lint_registry.rs @@ -1,4 +1,4 @@ -use std::{fs, io::Error}; +use std::{fs, io::Error, path::Path}; use just_template::{Template, tmpl}; @@ -67,7 +67,8 @@ pub fn gen_mod_file() -> Result<(), Error> { /// Generate lint metadata registry /// /// Parses each `.rs` file in `src/lints/` (excluding mod.rs and _init.rs), -/// extracts doc-comment metadata, and writes the result as JSON. +/// extracts doc-comment metadata, and writes the result as `registry.json` +/// in the cargo `OUT_DIR`. pub fn gen_lint_registry() -> Result<(), Error> { let root = std::env::current_dir()?; let lints_dir = root.join("src").join("lints"); @@ -102,7 +103,8 @@ pub fn gen_lint_registry() -> Result<(), Error> { }); let json = serde_json::json!({ "lints": lints }); - let out_path = root.join("registry.json"); + let out_dir = std::env::var("OUT_DIR").expect("OUT_DIR is not set"); + let out_path = Path::new(&out_dir).join("registry.json"); fs::write(&out_path, serde_json::to_string_pretty(&json).unwrap())?; Ok(()) } diff --git a/mingling_cli/src/bin/wrapper.rs b/mingling_cli/src/bin/wrapper.rs index b1aecf6..a47b926 100644 --- a/mingling_cli/src/bin/wrapper.rs +++ b/mingling_cli/src/bin/wrapper.rs @@ -1,9 +1,16 @@ use std::env; use std::ffi::OsString; -use std::path::PathBuf; +use std::fs; +use std::io; +use std::path::{Component, Path, PathBuf}; use std::process::{self, Command}; +use flate2::read::GzDecoder; +use sha2::{Digest, Sha256}; +use tar::Archive; + fn main() { + apply_update_if_present(); exec(); } @@ -45,3 +52,109 @@ fn exec() { } } } + +/// The update package staged by `mling update` at `{data_dir}/mingling/update.tar.gz`. +fn update_package_path() -> Option<PathBuf> { + dirs::data_dir().map(|data_dir| data_dir.join("mingling").join("update.tar.gz")) +} + +/// Apply a staged update, if any: unpack it over the installation directory +/// (never replacing the running wrapper itself), then remove the staged file. +/// This runs before forwarding to `mingling-cli`, so the new version is loaded +/// by this very invocation. +fn apply_update_if_present() { + let Some(update_path) = update_package_path() else { + return; + }; + if !update_path.is_file() { + return; + } + let Ok(current_exe) = env::current_exe() else { + return; + }; + + // The package mirrors the install layout: the wrapper lives at + // `<root>/bin/mling` and the archive root maps onto `<root>`, so entries + // like `bin/mingling-cli` replace the files next to this wrapper. + let Some(exe_dir) = current_exe.parent() else { + return; + }; + let Some(install_root) = exe_dir.parent() else { + return; + }; + + match unpack_update(&update_path, ¤t_exe, install_root) { + Ok(()) => { + // Record the applied package's checksum so `mling update` can tell + // that this installation is already up to date. + if let Some(checksum_path) = last_update_checksum_path() + && let Ok(checksum) = sha256_file(&update_path) + { + let _ = fs::write(checksum_path, checksum); + } + let _ = fs::remove_file(update_path); + } + Err(e) => eprintln!("mling: failed to apply update: {e}"), + } +} + +/// Extract `update.tar.gz` into `install_root`, skipping the running wrapper. +fn unpack_update( + update_path: &Path, + current_exe: &Path, + install_root: &Path, +) -> std::io::Result<()> { + let file = fs::File::open(update_path)?; + let mut archive = Archive::new(GzDecoder::new(file)); + + for entry in archive.entries()? { + let mut entry = entry?; + let entry_type = entry.header().entry_type(); + let rel_path = sanitize_relative_path(&entry.path()?); + if rel_path.as_os_str().is_empty() { + continue; + } + let dest = install_root.join(rel_path); + // The running executable cannot (and must not) replace itself. + if dest == current_exe { + continue; + } + if entry_type.is_dir() { + fs::create_dir_all(dest)?; + continue; + } + if !entry_type.is_file() { + continue; + } + if let Some(parent) = dest.parent() { + fs::create_dir_all(parent)?; + } + entry.unpack(dest)?; + } + Ok(()) +} + +/// Keep only normal path components so entries cannot escape `install_root`. +fn sanitize_relative_path(path: &Path) -> PathBuf { + let mut out = PathBuf::new(); + for component in path.components() { + if let Component::Normal(part) = component { + out.push(part); + } + } + out +} + +/// `{data_dir}/mingling/last-update.sha256`, where the wrapper records the +/// checksum of the update it applied. +fn last_update_checksum_path() -> Option<PathBuf> { + dirs::data_dir().map(|data_dir| data_dir.join("mingling").join("last-update.sha256")) +} + +/// The sha256 hex digest of a file. +fn sha256_file(path: &Path) -> io::Result<String> { + let mut file = fs::File::open(path)?; + let mut hasher = Sha256::new(); + io::copy(&mut file, &mut hasher)?; + Ok(format!("{:x}", hasher.finalize())) +} diff --git a/mingling_cli/src/config/cmd_cfg.rs b/mingling_cli/src/config/cmd_cfg.rs index c10195e..cde7772 100644 --- a/mingling_cli/src/config/cmd_cfg.rs +++ b/mingling_cli/src/config/cmd_cfg.rs @@ -1,8 +1,6 @@ use mingling::{ - LazyRes, Routable, ShellContext, Suggest, - macros::{ - arg, buffer, chain, command, completion, metadata, pack, r_println, renderer, suggest, - }, + Grouped, LazyRes, Routable, ShellContext, Suggest, Wrap, + macros::{arg, buffer, chain, command, completion, metadata, r_println, renderer, suggest}, metadata::Description, picker::{EntryPicker, PickerArg, value::Flag}, }; @@ -11,10 +9,17 @@ use crate::{Entry, Next, config::ResMlingConfig}; const FLAG_PAIR: PickerArg<Flag> = arg![pair: Flag]; -pack!(StateConfigEdit = (String, String)); -pack!(ResultConfigKeyValuePair = String); -pack!(ResultConfigValue = String); -pack!(ResultConfig = ()); +#[derive(Grouped, Wrap)] +pub struct StateConfigEdit((String, String)); + +#[derive(Grouped, Wrap)] +pub struct ResultConfigKeyValuePair(String); + +#[derive(Grouped, Wrap)] +pub struct ResultConfigValue(String); + +#[derive(Grouped)] +pub struct ResultConfig; #[command] pub fn cfg(args: Entry) -> Next { @@ -27,19 +32,19 @@ pub fn cfg(args: Entry) -> Next { match (key, value) { (Some(k), Some(v)) => { // Edit - StateConfigEdit::new((k, v)).into() + StateConfigEdit((k, v)).into() } (Some(k), None) => { // Display if *show_pair { - ResultConfigKeyValuePair::new(k).to_render() + ResultConfigKeyValuePair(k).to_render() } else { - ResultConfigValue::new(k).to_render() + ResultConfigValue(k).to_render() } } (None, None) => { // List - ResultConfig::new(()).to_render() + ResultConfig.to_render() } _ => { unreachable!("This path is unreachable given the positional parsing done by arg-picker") @@ -50,13 +55,13 @@ pub fn cfg(args: Entry) -> Next { #[chain] pub fn handle_state_config_edit(kv: StateConfigEdit, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_mut(); - config.edit(&kv.0, &kv.1); + config.edit(&kv.0.0, &kv.0.1); } #[renderer(buffer)] pub fn render_config_kvp(r: ResultConfigKeyValuePair, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_ref(); - let key = r.inner; + let key = r.0; let value = config.get(&key); r_println!( "\"{}\" = \"{}\"", @@ -68,7 +73,7 @@ pub fn render_config_kvp(r: ResultConfigKeyValuePair, config: &mut LazyRes<ResMl #[renderer(buffer)] pub fn render_config_value(r: ResultConfigValue, config: &mut LazyRes<ResMlingConfig>) { let config = config.get_ref(); - let key = r.inner; + let key = r.0; let value = config.get(&key); r_println!("{}", value) } @@ -104,7 +109,7 @@ pub fn escape_config_value(input: &str) -> String { } #[completion(EntryCfg)] -pub fn complete_config(_ctx: &ShellContext, config: &mut LazyRes<ResMlingConfig>) -> Suggest { +pub fn complete_config(_ctx: ShellContext, config: &mut LazyRes<ResMlingConfig>) -> Suggest { let config = config.get_ref(); let keys = config.get_hash_map().keys().cloned().collect::<Vec<_>>(); Suggest::from(keys).combine(suggest! { diff --git a/mingling_cli/src/lib.rs b/mingling_cli/src/lib.rs index fdd7636..d5a5b22 100644 --- a/mingling_cli/src/lib.rs +++ b/mingling_cli/src/lib.rs @@ -1,7 +1,7 @@ use mingling::{ - ShellContext, Suggest, + RenderResult, ShellContext, Suggest, consts::HELP_FLAG, - macros::{completion, gen_program, help, suggest}, + macros::{completion, gen_program, help, renderer, suggest}, }; use crate::{ @@ -21,15 +21,16 @@ pub mod message; pub mod metadata; pub mod pkg_mgr; pub mod proj_mgr; +pub mod updater; pub mod utils; #[help] pub fn help_global(_: EntryFallback) -> String { - include_str!("../help/help.txt").parse_color_code() + format!("{}\n", include_str!("../help/help.txt").parse_color_code()) } #[completion(EntryFallback)] -pub fn complete_global(_ctx: &ShellContext) -> Suggest { +pub fn complete_global(_ctx: ShellContext) -> Suggest { suggest! { HELP_FLAG: "Show help messages", ARG_FEATURES.clone(): "List of features to enable", @@ -41,4 +42,25 @@ pub fn complete_global(_ctx: &ShellContext) -> Suggest { } } +#[renderer] +pub fn handle_fallback(args: EntryFallback) -> RenderResult { + let mut r = RenderResult::new(); + let args = args.0; + if !args.is_empty() { + eprintln_cargo!( + r, + "{}", + format!("Unknown command `{}`", args.join(" ")).parse_color_code() + ) + } else { + hprintln_cargo!( + r, + "{}", + "Welcome to MinglingCLI, please use `mling -h` to see available commands" + .parse_color_code(), + ); + } + r +} + gen_program!(); diff --git a/mingling_cli/src/linter/cmd_explain.rs b/mingling_cli/src/linter/cmd_explain.rs index 5346255..1d99c62 100644 --- a/mingling_cli/src/linter/cmd_explain.rs +++ b/mingling_cli/src/linter/cmd_explain.rs @@ -1,10 +1,7 @@ use crate::{Next, eprintln_cargo, linter::registry::ResLintRegistry}; use mingling::{ - Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{ - arg, buffer, chain, completion, dispatcher, metadata, pack, pack_err, r_println, renderer, - routeify, - }, + Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, buffer, chain, completion, dispatcher, metadata, r_println, renderer, routeify}, metadata::Description, picker::EntryPicker, }; @@ -16,9 +13,14 @@ pub fn desc_explain() -> Description { "Explain the meaning of the specified Lint".into() } -pack!(StateExplainLint = String); -pack_err!(ErrorNoExplainLintProvided); -pack_err!(ErrorNoSuchLint = String); +#[derive(Grouped, Wrap)] +pub struct StateExplainLint(String); + +#[derive(Grouped, Default)] +pub struct ErrorNoExplainLintProvided; + +#[derive(Grouped, Wrap)] +pub struct ErrorNoSuchLint(String); #[derive(Debug, Default, Grouped)] pub struct ResultExplainLint { @@ -33,11 +35,9 @@ pub struct ResultExplainLint { #[chain(routeify)] pub fn handle_explain(args: EntryExplain) -> Next { let lint_name = args - .pick_or_route(&arg![String], || { - ErrorNoExplainLintProvided::default().to_chain() - }) + .pick_or_route(&arg![String], || ErrorNoExplainLintProvided.to_chain()) .to_result()?; - StateExplainLint::new(lint_name).into() + StateExplainLint(lint_name).into() } #[chain] @@ -46,9 +46,9 @@ pub fn handle_state_explain_lint( registry: &mut LazyRes<ResLintRegistry>, ) -> Next { let registry = registry.get_ref(); - let lint_name = p.inner; + let lint_name = p.0; let Some(entry) = registry.lints.iter().find(|l| l.name == lint_name) else { - return ErrorNoSuchLint::new(lint_name).to_chain(); + return ErrorNoSuchLint(lint_name).to_chain(); }; ResultExplainLint { lint_name: entry.name.clone(), @@ -87,7 +87,7 @@ pub fn render_error_no_such_lint( ) -> RenderResult { let mut r = RenderResult::new(); let registry = registry.get_ref(); - eprintln_cargo!(r, "No such lint: \"{}\"", err.info); + eprintln_cargo!(r, "No such lint: \"{}\"", err.0); r_println!(r, ""); r_println!(r, "Available lints:"); for entry in registry.lints.iter() { @@ -97,7 +97,7 @@ pub fn render_error_no_such_lint( } #[completion(EntryExplain)] -pub fn complete_explain(ctx: &ShellContext, registry: &mut LazyRes<ResLintRegistry>) -> Suggest { +pub fn complete_explain(ctx: ShellContext, registry: &mut LazyRes<ResLintRegistry>) -> Suggest { let registry = registry.get_ref(); if ctx.previous_word != "explain" { return Suggest::FileCompletion; diff --git a/mingling_cli/src/linter/cmd_lint.rs b/mingling_cli/src/linter/cmd_lint.rs index 38f2973..b49605f 100644 --- a/mingling_cli/src/linter/cmd_lint.rs +++ b/mingling_cli/src/linter/cmd_lint.rs @@ -1,14 +1,15 @@ use crate::linter::mlint_report::{MlintReport, StateLintReports}; use cargo_metadata::Metadata; use mingling::consts::REMAINS; -use mingling::macros::{arg, chain, completion, dispatcher, metadata, pack, suggest}; +use mingling::macros::{arg, chain, completion, dispatcher, metadata, suggest}; use mingling::metadata::Description; use mingling::picker::parselib::ParserStyle; use mingling::picker::{EntryPicker, PickerArg}; +use mingling::{Grouped, Wrap}; use mingling::{LazyRes, ShellContext, Suggest}; use tokio::task::JoinSet; -dispatcher!("lint", CMDLint => EntryLint); +dispatcher!("lint", EntryLint); const ARG_WITH_CHECKER: PickerArg<Option<String>> = arg![with_checker: Option<String>]; @@ -77,7 +78,8 @@ async fn linter_main(metadata: &Metadata) -> Vec<MlintReport> { all_reports } -pack!(StateBeginLinter = ()); +#[derive(Grouped, Wrap)] +pub struct StateBeginLinter(()); #[chain] pub fn handle_lint(args: EntryLint) -> StateBeginLinter { @@ -88,7 +90,7 @@ pub fn handle_lint(args: EntryLint) -> StateBeginLinter { // If with_checker is not set, proceed directly to the mingling lint phase let Some(with_checker) = with_checker else { - return StateBeginLinter::new(()); + return StateBeginLinter(()); }; let with_checker: Vec<&str> = with_checker.split(',').collect(); @@ -97,7 +99,7 @@ pub fn handle_lint(args: EntryLint) -> StateBeginLinter { // Run the outer checker (e.g. cargo check) with output passed through directly execute_checker(&with_checker, checker_args.as_slice()); - StateBeginLinter::new(()) + StateBeginLinter(()) } /// Run the outer checker (e.g. cargo check) with output passed through directly. @@ -135,11 +137,11 @@ pub async fn handle_state_begin_linter( ) -> StateLintReports { let metadata = metadata.get_ref().data(); let reports = linter_main(metadata).await; - StateLintReports::new(reports) + StateLintReports(reports) } #[completion(EntryLint)] -pub fn complete_lint(ctx: &ShellContext) -> Suggest { +pub fn complete_lint(ctx: ShellContext) -> Suggest { if mingling::picker::parselib::build_possible_flags( ParserStyle::global_style(), &ARG_WITH_CHECKER.into_info(), diff --git a/mingling_cli/src/linter/cmd_ra_lints.rs b/mingling_cli/src/linter/cmd_ra_lints.rs index 733d611..60b3e88 100644 --- a/mingling_cli/src/linter/cmd_ra_lints.rs +++ b/mingling_cli/src/linter/cmd_ra_lints.rs @@ -8,15 +8,15 @@ use crate::{linter::cmd_lint::EntryLint, metadata::setup::ResUsingJson}; // Aliases dispatcher!("ra-lint-clippy", - CMDLinterSupportRustAnalyzerWithClippy => EntryLinterSupportRustAnalyzerWithClippy + EntryLinterSupportRustAnalyzerWithClippy ); dispatcher!("ra-lint-check", - CMDLinterSupportRustAnalyzerWithCheck => EntryLinterSupportRustAnalyzerWithCheck + EntryLinterSupportRustAnalyzerWithCheck ); dispatcher!("ra-lint", - CMDLinterSupportRustAnalyzer => EntryLinterSupportRustAnalyzer + EntryLinterSupportRustAnalyzer ); #[chain] diff --git a/mingling_cli/src/linter/mlint_report.rs b/mingling_cli/src/linter/mlint_report.rs index b594b9d..d7bf652 100644 --- a/mingling_cli/src/linter/mlint_report.rs +++ b/mingling_cli/src/linter/mlint_report.rs @@ -9,8 +9,8 @@ use cargo_metadata::{Message, PackageId}; use annotate_snippets::level::{ERROR, HELP, NOTE, WARNING}; use annotate_snippets::{AnnotationKind, Group, Patch, Renderer, Snippet}; -use mingling::macros::{buffer, chain, pack, r_append, r_eprintln, renderer}; -use mingling::{RendererInvoker, Routable}; +use mingling::macros::{buffer, chain, r_append, r_eprintln, renderer}; +use mingling::{Grouped, RendererInvoker, Routable, Wrap}; use crate::Next; use crate::metadata::setup::ResUsingJson; @@ -416,22 +416,25 @@ impl MlintReport { } } -pack!(StateLintReports = Vec<MlintReport>); -pack!(ResultLintReportsAnnotateSnippet = Vec<MlintReport>); -pack!(ResultLintReportsJson = Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct StateLintReports(pub Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct ResultLintReportsAnnotateSnippet(Vec<MlintReport>); +#[derive(Grouped, Wrap)] +pub struct ResultLintReportsJson(Vec<MlintReport>); #[chain] pub fn handle_state_lint_reports(reports: StateLintReports, using_json: &ResUsingJson) -> Next { if using_json.using { - ResultLintReportsJson::new(reports.inner).to_render() + ResultLintReportsJson(reports.0).to_render() } else { - ResultLintReportsAnnotateSnippet::new(reports.inner).to_render() + ResultLintReportsAnnotateSnippet(reports.0).to_render() } } #[renderer(buffer)] pub fn render_lint_reports(reports: ResultLintReportsAnnotateSnippet) { - for report in reports.inner { + for report in reports.0 { r_eprintln!("{}", report.to_annotate_snippet_render()); } } @@ -441,7 +444,7 @@ pub fn render_lint_reports_json( reports: ResultLintReportsJson, message_renderer: &RendererInvoker<Message>, ) { - for report in reports.inner { + for report in reports.0 { let message = report.to_compiler_message(); let result = message_renderer.invoke(message); r_append!(result); diff --git a/mingling_cli/src/linter/registry.rs b/mingling_cli/src/linter/registry.rs index 79f3225..b9f82fa 100644 --- a/mingling_cli/src/linter/registry.rs +++ b/mingling_cli/src/linter/registry.rs @@ -26,8 +26,9 @@ pub struct LintMetadata { #[program_setup] pub fn lint_registry_setup(p: &mut Program<ThisProgram>) { p.with_resource(ResLintRegistry::lazy_init(|| { - let registry: ResLintRegistry = serde_json::from_str(include_str!("../../registry.json")) - .expect("failed to parse embedded registry.json"); + let registry: ResLintRegistry = + serde_json::from_str(include_str!(concat!(env!("OUT_DIR"), "/registry.json"))) + .expect("failed to parse embedded registry.json"); registry })); } diff --git a/mingling_cli/src/metadata/cmd_metadata.rs b/mingling_cli/src/metadata/cmd_metadata.rs index 3ee9f09..7f8d4ad 100644 --- a/mingling_cli/src/metadata/cmd_metadata.rs +++ b/mingling_cli/src/metadata/cmd_metadata.rs @@ -1,7 +1,7 @@ use cargo_metadata::Metadata; use mingling::{ - LazyRes, - macros::{chain, dispatcher, metadata, pack}, + Grouped, LazyRes, Wrap, + macros::{chain, dispatcher, metadata}, metadata::Description, }; @@ -16,7 +16,8 @@ pub fn desc_metadata() -> Description { .into() } -pack!(ResultMetadata = ResMetadata); +#[derive(Grouped, Wrap)] +pub struct ResultMetadata(ResMetadata); #[chain] pub fn handle_metadata(_: EntryMetadata, metadata: &mut LazyRes<ResMetadata>) -> Metadata { diff --git a/mingling_cli/src/pkg_mgr.rs b/mingling_cli/src/pkg_mgr.rs index e140991..8493804 100644 --- a/mingling_cli/src/pkg_mgr.rs +++ b/mingling_cli/src/pkg_mgr.rs @@ -8,16 +8,23 @@ pub mod cmd_uninstall; use std::path::PathBuf; use mingling::{ - Program, RenderResult, - macros::{pack_err, program_setup, r_println, renderer}, + Grouped, Program, RenderResult, Wrap, + macros::{program_setup, r_println, renderer}, }; use crate::{ThisProgram, eprintln_cargo, hprintln_cargo}; -pack_err!(ErrorRootPackageNotFound); -pack_err!(ErrorNoDataDirectory); -pack_err!(ErrorPackageSpecInvalid = String); -pack_err!(ErrorPackageNameRequired); +#[derive(Grouped, Default)] +pub struct ErrorRootPackageNotFound; + +#[derive(Grouped, Default)] +pub struct ErrorNoDataDirectory; + +#[derive(Grouped, Wrap)] +pub struct ErrorPackageSpecInvalid(String); + +#[derive(Grouped, Default)] +pub struct ErrorPackageNameRequired; /// The `mingling/packages` packages directory under the user's data directory. #[derive(Debug, Default, Clone)] @@ -55,7 +62,7 @@ pub fn render_error_no_data_directory(_: ErrorNoDataDirectory) -> RenderResult { #[renderer] pub fn render_error_package_spec_invalid(err: ErrorPackageSpecInvalid) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "invalid package spec: {}", err.info); + eprintln_cargo!(r, "invalid package spec: {}", err.0); r } diff --git a/mingling_cli/src/pkg_mgr/cmd_install.rs b/mingling_cli/src/pkg_mgr/cmd_install.rs index ddcef7d..c7dcaef 100644 --- a/mingling_cli/src/pkg_mgr/cmd_install.rs +++ b/mingling_cli/src/pkg_mgr/cmd_install.rs @@ -2,9 +2,10 @@ use std::{env, fs, io, path::PathBuf, process::Command}; use cargo_metadata::TargetKind; use mingling::{ - Grouped, LazyRes, RenderResult, Routable, - macros::{chain, command, metadata, pack_err, renderer, routeify}, + Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, Wrap, + macros::{arg, chain, command, completion, metadata, renderer, routeify, suggest}, metadata::Description, + picker::{EntryPicker, PickerArg, value::Flag}, }; use crate::{ @@ -14,8 +15,18 @@ use crate::{ println_cargo, }; -pack_err!(ErrorBuildFailed = String); -pack_err!(ErrorBinaryNotFound = String); +#[derive(Grouped, Wrap)] +pub struct ErrorBuildFailed(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorBinaryNotFound(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorPkgEnableFailed(String); + +/// Flag: `--enable` — run `mling pkg-enable` after a successful install +/// to enable the package being installed. +pub static ARG_ENABLE: PickerArg<Flag> = arg![enable: Flag]; /// Resolved install paths, used by the build step. #[derive(Debug, Default, Grouped)] @@ -24,6 +35,7 @@ pub struct StateInstallBuild { pub install_dir: PathBuf, pub release_dir: PathBuf, pub exe_suffix: &'static str, + pub enable: bool, } /// State after `cargo build --release`, used by the copy step. @@ -33,6 +45,16 @@ pub struct StateInstallCopy { pub release_dir: PathBuf, pub exe_suffix: &'static str, pub installed: Vec<PathBuf>, + pub enable: bool, +} + +/// State after the copy step when `--enable` was given: run `mling pkg-enable`. +#[derive(Debug, Default, Grouped)] +pub struct StateInstallEnable { + pub install_dir: PathBuf, + pub installed: Vec<PathBuf>, + pub name: String, + pub version: String, } #[derive(Debug, Default, Grouped)] @@ -49,17 +71,22 @@ pub fn desc_install() -> Description { } #[command(routeify)] -pub fn install(packages_dir: &ResPackagesDir, metadata: &mut LazyRes<ResMetadata>) -> Next { +pub fn install( + args: EntryInstall, + packages_dir: &ResPackagesDir, + metadata: &mut LazyRes<ResMetadata>, +) -> Next { + let enable = args.pick(&ARG_ENABLE).to_result()?; let metadata = metadata.get_ref().data(); let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let root_package = metadata .root_package() .or_else(|| metadata.workspace_packages().first().copied()) - .ok_or(ErrorRootPackageNotFound::default())?; + .ok_or(ErrorRootPackageNotFound)?; StateInstallBuild { workspace_root: metadata.workspace_root.clone().into_std_path_buf(), @@ -69,6 +96,7 @@ pub fn install(packages_dir: &ResPackagesDir, metadata: &mut LazyRes<ResMetadata .join("release") .into_std_path_buf(), exe_suffix: env::consts::EXE_SUFFIX, + enable: enable.bool(), } .to_chain() } @@ -80,11 +108,9 @@ pub fn handle_state_install_build(state: StateInstallBuild) -> Next { .args(["build", "--release"]) .current_dir(&state.workspace_root) .status() - .map_err(|e| { - ErrorBuildFailed::new(format!("failed to run `cargo build --release`: {e}")) - })?; + .map_err(|e| ErrorBuildFailed(format!("failed to run `cargo build --release`: {e}")))?; if !status.success() { - return ErrorBuildFailed::new(format!("`cargo build --release` failed with {status}")) + return ErrorBuildFailed(format!("`cargo build --release` failed with {status}")) .to_chain(); } @@ -93,6 +119,7 @@ pub fn handle_state_install_build(state: StateInstallBuild) -> Next { release_dir: state.release_dir, exe_suffix: state.exe_suffix, installed: vec![], + enable: state.enable, } .to_chain() } @@ -122,7 +149,7 @@ pub fn handle_state_install_copy( let bin_file = format!("{}{}", target.name, state.exe_suffix); let src = state.release_dir.join(&bin_file); if !src.is_file() { - return ErrorBinaryNotFound::new(bin_file).to_chain(); + return ErrorBinaryNotFound(bin_file).to_chain(); } let dst = state.install_dir.join(&bin_file); fs::copy(&src, &dst).map_err(|e| { @@ -153,6 +180,43 @@ pub fn handle_state_install_copy( } } + if state.enable { + let root_package = metadata + .root_package() + .or_else(|| metadata.workspace_packages().first().copied()) + .ok_or(ErrorRootPackageNotFound)?; + return StateInstallEnable { + install_dir: state.install_dir, + installed: state.installed, + name: root_package.name.to_string(), + version: root_package.version.to_string(), + } + .to_chain(); + } + + ResultInstall { + install_dir: state.install_dir, + installed: state.installed, + } + .to_chain() +} + +/// Step 3 (optional): enable the installed package via `mling pkg-enable` +/// when `--enable` was given. +#[chain(routeify)] +pub fn handle_state_install_enable(state: StateInstallEnable) -> Next { + let spec = format!("{}@{}", state.name, state.version); + let status = Command::new("mling") + .args(["pkg-enable", &spec]) + .status() + .map_err(|e| { + ErrorPkgEnableFailed(format!("failed to run `mling pkg-enable {spec}`: {e}")) + })?; + if !status.success() { + return ErrorPkgEnableFailed(format!("`mling pkg-enable {spec}` failed with {status}")) + .to_chain(); + } + ResultInstall { install_dir: state.install_dir, installed: state.installed, @@ -173,13 +237,30 @@ pub fn render_result_install(result: ResultInstall) -> RenderResult { #[renderer] pub fn render_error_build_failed(err: ErrorBuildFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_binary_not_found(err: ErrorBinaryNotFound) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "binary not found: {}", err.info); + eprintln_cargo!(r, "binary not found: {}", err.0); r } + +#[renderer] +pub fn render_error_pkg_enable_failed(err: ErrorPkgEnableFailed) -> RenderResult { + let mut r = RenderResult::new(); + eprintln_cargo!(r, "{}", err.0); + r +} + +#[completion(EntryInstall)] +pub fn complete_install(ctx: ShellContext) -> Suggest { + if ctx.previous_word != "install" { + return Suggest::FileCompletion; + } + suggest! { + ARG_ENABLE: "Enable the package after installing (runs `mling pkg-enable`)" + } +} diff --git a/mingling_cli/src/pkg_mgr/cmd_internal_loadpkgs.rs b/mingling_cli/src/pkg_mgr/cmd_internal_loadpkgs.rs index b4928ce..f0ac88a 100644 --- a/mingling_cli/src/pkg_mgr/cmd_internal_loadpkgs.rs +++ b/mingling_cli/src/pkg_mgr/cmd_internal_loadpkgs.rs @@ -4,8 +4,8 @@ use std::{ }; use mingling::{ - Routable, - macros::{buffer, command, pack, r_println, renderer, routeify}, + Grouped, Routable, Wrap, + macros::{buffer, command, r_println, renderer, routeify}, }; use crate::{ @@ -14,16 +14,18 @@ use crate::{ }; // Version directory paths of every enabled package. -pack!(ResultLoadPkgsPaths = Vec<PathBuf>); +#[derive(Grouped, Wrap)] +pub struct ResultLoadPkgsPaths(Vec<PathBuf>); // Completion script paths of every enabled package. -pack!(ResultLoadPkgsComps = Vec<PathBuf>); +#[derive(Grouped, Wrap)] +pub struct ResultLoadPkgsComps(Vec<PathBuf>); #[command(node = "__loadpkgs_path", routeify)] pub fn load_packages_paths(packages_dir: &ResPackagesDir) -> Next { let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let paths = enabled_version_dirs(packages_dir).map_err(|e| { io::Error::new( @@ -31,14 +33,14 @@ pub fn load_packages_paths(packages_dir: &ResPackagesDir) -> Next { format!("failed to read {}: {e}", packages_dir.display()), ) })?; - ResultLoadPkgsPaths::new(paths).to_chain() + ResultLoadPkgsPaths(paths).to_chain() } #[command(node = "__loadpkgs_comp_scripts", routeify)] pub fn load_packages_comp_scripts(packages_dir: &ResPackagesDir) -> Next { let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let scripts = comp_scripts(packages_dir).map_err(|e| { io::Error::new( @@ -46,19 +48,19 @@ pub fn load_packages_comp_scripts(packages_dir: &ResPackagesDir) -> Next { format!("failed to read {}: {e}", packages_dir.display()), ) })?; - ResultLoadPkgsComps::new(scripts).to_chain() + ResultLoadPkgsComps(scripts).to_chain() } #[renderer(buffer)] pub fn render_result_load_pkgs_paths(r: ResultLoadPkgsPaths) { - for path in r.inner { + for path in r.0 { r_println!("{}", path.display()); } } #[renderer(buffer)] pub fn render_result_load_pkgs_comps(r: ResultLoadPkgsComps) { - for path in r.inner { + for path in r.0 { r_println!("{}", path.display()); } } diff --git a/mingling_cli/src/pkg_mgr/cmd_pkg_disable.rs b/mingling_cli/src/pkg_mgr/cmd_pkg_disable.rs index 041bb09..ea6997f 100644 --- a/mingling_cli/src/pkg_mgr/cmd_pkg_disable.rs +++ b/mingling_cli/src/pkg_mgr/cmd_pkg_disable.rs @@ -1,8 +1,8 @@ use std::{fs, io}; use mingling::{ - Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{arg, chain, command, completion, metadata, pack, pack_err, renderer, routeify}, + Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, chain, command, completion, metadata, renderer, routeify}, metadata::Description, picker::{EntryPicker, PickerArg}, }; @@ -18,10 +18,12 @@ use crate::{ /// Positional argument: package name pub static ARG_NAME: PickerArg<String> = arg![String]; -pack_err!(ErrorPackageNotEnabled = String); +#[derive(Grouped, Wrap)] +pub struct ErrorPackageNotEnabled(String); // The name of the package to disable -pack!(StatePkgDisable = String); +#[derive(Grouped, Wrap)] +pub struct StatePkgDisable(String); #[derive(Debug, Default, Grouped)] pub struct ResultPkgDisable { @@ -37,30 +39,30 @@ pub fn desc_pkg_disable() -> Description { #[command(node = "pkg-disable", routeify)] pub fn package_disable(args: EntryPkgDisable, packages_dir: &ResPackagesDir) -> Next { let name = args - .pick_or_route(&ARG_NAME, || ErrorPackageNameRequired::default().to_chain()) + .pick_or_route(&ARG_NAME, || ErrorPackageNameRequired.to_chain()) .to_result()?; let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } if name.contains('/') || name.contains('\\') || name.contains("..") || name.contains('@') { - return ErrorPackageSpecInvalid::new(name).to_chain(); + return ErrorPackageSpecInvalid(name).to_chain(); } - StatePkgDisable::new(name).to_chain() + StatePkgDisable(name).to_chain() } #[chain(routeify)] pub fn handle_state_pkg_disable(p: StatePkgDisable, packages_dir: &ResPackagesDir) -> Next { - let name = p.inner; + let name = p.0; let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let file = packages_dir.join(&name); if !file.is_file() { - return ErrorPackageNotEnabled::new(name).to_chain(); + return ErrorPackageNotEnabled(name).to_chain(); } fs::remove_file(&file).map_err(|e| { io::Error::new( @@ -86,12 +88,12 @@ pub fn render_result_pkg_disable(result: ResultPkgDisable) -> RenderResult { #[renderer] pub fn render_error_package_not_enabled(err: ErrorPackageNotEnabled) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "package is not enabled: {}", err.info); + eprintln_cargo!(r, "package is not enabled: {}", err.0); r } #[completion(EntryPkgDisable)] -pub fn complete_pkg_disable(ctx: &ShellContext, packages_dir: &ResPackagesDir) -> Suggest { +pub fn complete_pkg_disable(ctx: ShellContext, packages_dir: &ResPackagesDir) -> Suggest { if ctx.previous_word != "pkg-disable" { return Suggest::FileCompletion; } diff --git a/mingling_cli/src/pkg_mgr/cmd_pkg_enable.rs b/mingling_cli/src/pkg_mgr/cmd_pkg_enable.rs index 8f6a234..377bd33 100644 --- a/mingling_cli/src/pkg_mgr/cmd_pkg_enable.rs +++ b/mingling_cli/src/pkg_mgr/cmd_pkg_enable.rs @@ -1,8 +1,8 @@ use std::{fs, io}; use mingling::{ - Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{arg, chain, command, completion, metadata, pack, pack_err, renderer, routeify}, + Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, chain, command, completion, metadata, renderer, routeify}, metadata::Description, picker::{EntryPicker, PickerArg}, }; @@ -18,8 +18,11 @@ use crate::{ /// Positional argument: package spec (`foo`, `foo@0`, `foo@0.1`, `foo@0.1.2`) pub static ARG_SPEC: PickerArg<String> = arg![String]; -pack_err!(ErrorNoMatchingVersion = String); -pack!(StatePkgEnable = (String, String)); +#[derive(Grouped, Wrap)] +pub struct ErrorNoMatchingVersion(String); + +#[derive(Grouped, Wrap)] +pub struct StatePkgEnable((String, String)); #[derive(Debug, Default, Grouped)] pub struct ResultPkgEnable { @@ -35,14 +38,14 @@ pub fn desc_pkg_enable() -> Description { #[command(node = "pkg-enable", routeify)] pub fn package_enable(args: EntryPkgEnable, packages_dir: &ResPackagesDir) -> Next { let spec = args - .pick_or_route(&ARG_SPEC, || ErrorPackageNameRequired::default().to_chain()) + .pick_or_route(&ARG_SPEC, || ErrorPackageNameRequired.to_chain()) .to_result()?; let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } if spec.contains('/') || spec.contains('\\') || spec.contains("..") { - return ErrorPackageSpecInvalid::new(spec).to_chain(); + return ErrorPackageSpecInvalid(spec).to_chain(); } let (name, version_part) = match spec.split_once('@') { @@ -78,18 +81,18 @@ pub fn package_enable(args: EntryPkgEnable, packages_dir: &ResPackagesDir) -> Ne } let Some((_, version)) = candidates.into_iter().max_by(|a, b| a.1.cmp(&b.1)) else { - return ErrorNoMatchingVersion::new(spec).to_chain(); + return ErrorNoMatchingVersion(spec).to_chain(); }; - StatePkgEnable::new((name, version.to_string())).to_chain() + StatePkgEnable((name, version.to_string())).to_chain() } #[chain(routeify)] pub fn handle_state_pkg_enable(p: StatePkgEnable, packages_dir: &ResPackagesDir) -> Next { - let (name, version) = p.inner; + let (name, version) = p.0; let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let file = packages_dir.join(&name); @@ -110,12 +113,12 @@ pub fn render_result_pkg_enable(result: ResultPkgEnable) -> RenderResult { #[renderer] pub fn render_error_no_matching_version(err: ErrorNoMatchingVersion) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "no matching version for: {}", err.info); + eprintln_cargo!(r, "no matching version for: {}", err.0); r } #[completion(EntryPkgEnable)] -pub fn complete_pkg_enable(ctx: &ShellContext, packages_dir: &ResPackagesDir) -> Suggest { +pub fn complete_pkg_enable(ctx: ShellContext, packages_dir: &ResPackagesDir) -> Suggest { if ctx.previous_word != "pkg-enable" { return Suggest::FileCompletion; } diff --git a/mingling_cli/src/pkg_mgr/cmd_pkg_show.rs b/mingling_cli/src/pkg_mgr/cmd_pkg_show.rs index 88c79ef..ea26021 100644 --- a/mingling_cli/src/pkg_mgr/cmd_pkg_show.rs +++ b/mingling_cli/src/pkg_mgr/cmd_pkg_show.rs @@ -3,7 +3,7 @@ use std::{collections::BTreeMap, fs, io}; use colored::Colorize; use mingling::{ Grouped, RenderResult, Routable, - macros::{buffer, command, metadata, pack_err, r_println, renderer, routeify}, + macros::{buffer, command, metadata, r_println, renderer, routeify}, metadata::Description, }; @@ -15,8 +15,10 @@ use crate::{ #[derive(Debug, Default, Clone)] pub struct PkgShowEntry { pub name: String, + /// Enabled version, from the content of the enable file. pub enabled: Option<String>, + /// Installed versions, newest first. pub versions: Vec<String>, } @@ -31,13 +33,14 @@ pub fn desc_pkg_show() -> Description { "Show locally installed packages".into() } -pack_err!(ErrorNoPackagesInstalled); +#[derive(Grouped, Default)] +pub struct ErrorNoPackagesInstalled; #[command(node = "pkg-show", routeify)] pub fn package_show(packages_dir: &ResPackagesDir) -> Next { let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let mut entries: BTreeMap<String, PkgShowEntry> = BTreeMap::new(); @@ -84,7 +87,7 @@ pub fn package_show(packages_dir: &ResPackagesDir) -> Next { let packages: Vec<PkgShowEntry> = entries.into_values().collect(); if packages.is_empty() { - return ErrorNoPackagesInstalled::default().into(); + return ErrorNoPackagesInstalled.into(); } ResultPkgShow { packages }.to_chain() diff --git a/mingling_cli/src/pkg_mgr/cmd_uninstall.rs b/mingling_cli/src/pkg_mgr/cmd_uninstall.rs index 2b288d6..0c8781a 100644 --- a/mingling_cli/src/pkg_mgr/cmd_uninstall.rs +++ b/mingling_cli/src/pkg_mgr/cmd_uninstall.rs @@ -1,8 +1,8 @@ use std::{fs, io, path::PathBuf}; use mingling::{ - LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{arg, chain, command, completion, metadata, pack, pack_err, renderer, routeify}, + Grouped, LazyRes, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, chain, command, completion, metadata, renderer, routeify}, metadata::Description, picker::{EntryPicker, PickerArg}, }; @@ -20,16 +20,20 @@ use crate::{ pub static ARG_PACKAGE: PickerArg<Option<String>> = arg![Option<String>]; // Directory names to remove, e.g. `["omg@0.1.0", "omg@0.1.1"]` -pack!(StateUninstallPackages = Vec<String>); +#[derive(Grouped, Wrap)] +pub struct StateUninstallPackages(Vec<String>); // Directories that were successfully removed. -pack!(ResultPackageUninstalled = Vec<PathBuf>); +#[derive(Grouped, Wrap)] +pub struct ResultPackageUninstalled(Vec<PathBuf>); // Directories that were not installed. -pack_err!(ErrorPackageNotInstall = Vec<PathBuf>); +#[derive(Grouped, Wrap)] +pub struct ErrorPackageNotInstall(Vec<PathBuf>); // No installed package matched the given spec. -pack_err!(ErrorNoMatchingPackages); +#[derive(Grouped, Default)] +pub struct ErrorNoMatchingPackages; /// `{data_dir}/mingling/packages` #[metadata(EntryUninstall)] @@ -46,7 +50,7 @@ pub fn uninstall( let spec = args.pick(&ARG_PACKAGE).to_result()?; let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let targets = match spec { @@ -56,13 +60,13 @@ pub fn uninstall( let root_package = metadata .root_package() .or_else(|| metadata.workspace_packages().first().copied()) - .ok_or(ErrorRootPackageNotFound::default())?; + .ok_or(ErrorRootPackageNotFound)?; vec![format!("{}@{}", root_package.name, root_package.version)] } // `name` matches every installed version, `name@version` matches exactly Some(spec) => { if spec.contains('/') || spec.contains('\\') || spec.contains("..") { - return ErrorPackageSpecInvalid::new(spec).to_chain(); + return ErrorPackageSpecInvalid(spec).to_chain(); } if spec.contains('@') { vec![spec] @@ -87,7 +91,7 @@ pub fn uninstall( } }; - StateUninstallPackages::new(targets).to_chain() + StateUninstallPackages(targets).to_chain() } #[chain(routeify)] @@ -97,13 +101,13 @@ pub fn handle_state_uninstall_packages( ) -> Next { let packages_dir = &packages_dir.path; if packages_dir.as_os_str().is_empty() { - return ErrorNoDataDirectory::default().to_chain(); + return ErrorNoDataDirectory.to_chain(); } let mut removed = Vec::new(); let mut not_installed = Vec::new(); - for name in p.inner { + for name in p.0 { let dir = packages_dir.join(&name); if !dir.exists() { not_installed.push(dir); @@ -116,18 +120,18 @@ pub fn handle_state_uninstall_packages( } if removed.is_empty() && not_installed.is_empty() { - return ErrorNoMatchingPackages::default().to_chain(); + return ErrorNoMatchingPackages.to_chain(); } if !removed.is_empty() { - return ResultPackageUninstalled::new(removed).to_chain(); + return ResultPackageUninstalled(removed).to_chain(); } - ErrorPackageNotInstall::new(not_installed).to_chain() + ErrorPackageNotInstall(not_installed).to_chain() } #[renderer] pub fn render_result_package_uninstalled(r: ResultPackageUninstalled) -> RenderResult { let mut result = RenderResult::new(); - for dir in r.inner { + for dir in r.0 { println_cargo!(result, "Uninstalled: {}", dir.display()); } result @@ -136,7 +140,7 @@ pub fn render_result_package_uninstalled(r: ResultPackageUninstalled) -> RenderR #[renderer] pub fn render_error_package_not_install(err: ErrorPackageNotInstall) -> RenderResult { let mut result = RenderResult::new(); - for dir in err.info { + for dir in err.0 { eprintln_cargo!(result, "not installed: {}", dir.display()); } result @@ -150,7 +154,7 @@ pub fn render_error_no_matching_packages(_: ErrorNoMatchingPackages) -> RenderRe } #[completion(EntryUninstall)] -pub fn complete_uninstall(ctx: &ShellContext, packages_dir: &ResPackagesDir) -> Suggest { +pub fn complete_uninstall(ctx: ShellContext, packages_dir: &ResPackagesDir) -> Suggest { if ctx.previous_word != "uninstall" { return Suggest::FileCompletion; } diff --git a/mingling_cli/src/proj_mgr/cmd_class_add.rs b/mingling_cli/src/proj_mgr/cmd_class_add.rs index 9c729a9..f42bbff 100644 --- a/mingling_cli/src/proj_mgr/cmd_class_add.rs +++ b/mingling_cli/src/proj_mgr/cmd_class_add.rs @@ -6,8 +6,8 @@ use std::{ use just_fmt::{camel_case, kebab_case, pascal_case, snake_case}; use just_template::Template; use mingling::{ - Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, - macros::{arg, chain, command, completion, metadata, pack, pack_err, renderer, routeify}, + Grouped, RenderResult, Routable, ShellContext, Suggest, SuggestItem, Wrap, + macros::{arg, chain, command, completion, metadata, renderer, routeify}, metadata::Description, picker::EntryPicker, res::ResCurrentDir, @@ -29,7 +29,8 @@ pub struct ClassEntry { pub description: String, } -pack!(StateClassAdd = (String, String)); +#[derive(Grouped, Wrap)] +pub struct StateClassAdd((String, String)); /// Result of adding a class: the generated file path. #[derive(Debug, Default, Grouped)] @@ -37,19 +38,28 @@ pub struct ResultClassAdd { pub output: PathBuf, } -pack_err!(ErrorClassNameRequired = ()); -pack_err!(ErrorClassConfigMissing = String); -pack_err!(ErrorClassNotFound = String); -pack_err!(ErrorClassTemplateMissing = String); -pack_err!(ErrorClassWriteFailed = String); +#[derive(Grouped)] +pub struct ErrorClassNameRequired; + +#[derive(Grouped, Wrap)] +pub struct ErrorClassConfigMissing(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorClassNotFound(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorClassTemplateMissing(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorClassWriteFailed(String); #[command(node = "class-add", routeify)] pub fn class_add(args: EntryClassAdd) -> Next { let (class_name, name) = args - .pick_or_route(&arg![String], || ErrorClassNameRequired::new(()).to_chain()) - .pick_or_route(&arg![String], || ErrorClassNameRequired::new(()).to_chain()) + .pick_or_route(&arg![String], || ErrorClassNameRequired.to_chain()) + .pick_or_route(&arg![String], || ErrorClassNameRequired.to_chain()) .to_result()?; - StateClassAdd::new((class_name, name)).to_chain() + StateClassAdd((class_name, name)).to_chain() } /// Walk upward from `start` to find the first directory containing `.mling`. @@ -91,11 +101,11 @@ fn deverbatim(path: &Path) -> PathBuf { /// name-derived parameters into `<output-dir>/<snake_case>.rs`. #[chain(routeify)] pub fn handle_state_class_add(state: StateClassAdd, cwd: &ResCurrentDir) -> Next { - let (class_name, name) = state.inner; + let (class_name, name) = state.0; // Resolve the project root: the nearest ancestor directory with `.mling`. let Some(project_root) = find_project_root(cwd) else { - return ErrorClassConfigMissing::new(format!( + return ErrorClassConfigMissing(format!( "no `.mling` directory found from {} upward; run this inside a mingling project", cwd.display() )) @@ -105,14 +115,14 @@ pub fn handle_state_class_add(state: StateClassAdd, cwd: &ResCurrentDir) -> Next // Read `.mling/classes.toml` (the class registry). let classes_path = project_root.join(".mling").join("classes.toml"); let content = fs::read_to_string(&classes_path).map_err(|e| { - ErrorClassConfigMissing::new(format!("failed to read {}: {e}", classes_path.display())) + ErrorClassConfigMissing(format!("failed to read {}: {e}", classes_path.display())) })?; let classes = parse_classes(&content) - .map_err(|e| ErrorClassConfigMissing::new(format!("invalid classes.toml: {e}")))?; + .map_err(|e| ErrorClassConfigMissing(format!("invalid classes.toml: {e}")))?; // Find the requested class type. let Some(entry) = classes.iter().find(|c| c.name == class_name) else { - return ErrorClassNotFound::new(format!( + return ErrorClassNotFound(format!( "class `{class_name}` not found in {}", classes_path.display() )) @@ -122,7 +132,7 @@ pub fn handle_state_class_add(state: StateClassAdd, cwd: &ResCurrentDir) -> Next // Read the class template (relative to `.mling/`). let template_path = project_root.join(".mling").join(&entry.template); let template_content = fs::read_to_string(&template_path).map_err(|e| { - ErrorClassTemplateMissing::new(format!("failed to read {}: {e}", template_path.display())) + ErrorClassTemplateMissing(format!("failed to read {}: {e}", template_path.display())) })?; // Derive the name variants used by the template placeholders. @@ -139,7 +149,7 @@ pub fn handle_state_class_add(state: StateClassAdd, cwd: &ResCurrentDir) -> Next tmpl.insert_param("upper_snake_case".to_string(), upper_snake); tmpl.insert_param("camel_case".to_string(), camel); let expanded = tmpl.expand().ok_or_else(|| { - ErrorClassWriteFailed::new(format!( + ErrorClassWriteFailed(format!( "failed to expand class template: {}", template_path.display() )) @@ -149,11 +159,10 @@ pub fn handle_state_class_add(state: StateClassAdd, cwd: &ResCurrentDir) -> Next let output_dir = project_root.join(&entry.output_dir); let output = output_dir.join(format!("{snake}.rs")); fs::create_dir_all(&output_dir).map_err(|e| { - ErrorClassWriteFailed::new(format!("failed to create {}: {e}", output_dir.display())) - })?; - fs::write(&output, expanded).map_err(|e| { - ErrorClassWriteFailed::new(format!("failed to write {}: {e}", output.display())) + ErrorClassWriteFailed(format!("failed to create {}: {e}", output_dir.display())) })?; + fs::write(&output, expanded) + .map_err(|e| ErrorClassWriteFailed(format!("failed to write {}: {e}", output.display())))?; ResultClassAdd { output }.to_chain() } @@ -215,33 +224,33 @@ pub fn render_error_class_name_required(_err: ErrorClassNameRequired) -> RenderR #[renderer] pub fn render_error_class_config_missing(err: ErrorClassConfigMissing) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_class_not_found(err: ErrorClassNotFound) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_class_template_missing(err: ErrorClassTemplateMissing) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_class_write_failed(err: ErrorClassWriteFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[completion(EntryClassAdd)] -pub fn complete_class_add(ctx: &ShellContext, cwd: &ResCurrentDir) -> Suggest { +pub fn complete_class_add(ctx: ShellContext, cwd: &ResCurrentDir) -> Suggest { if ctx.previous_word != "class-add" { return Suggest::file_comp(); } diff --git a/mingling_cli/src/proj_mgr/cmd_proj_init.rs b/mingling_cli/src/proj_mgr/cmd_proj_init.rs index 1ef8d1e..edad83c 100644 --- a/mingling_cli/src/proj_mgr/cmd_proj_init.rs +++ b/mingling_cli/src/proj_mgr/cmd_proj_init.rs @@ -7,8 +7,8 @@ use std::{ use just_fmt::snake_case; use just_template::Template; use mingling::{ - Grouped, LazyRes, RenderResult, Routable, - macros::{arg, chain, command, metadata, pack, pack_err, r_println, renderer, routeify}, + Grouped, LazyRes, RenderResult, Routable, Wrap, + macros::{arg, chain, command, metadata, r_println, renderer, routeify}, metadata::Description, picker::EntryPicker, res::ResCurrentDir, @@ -30,8 +30,11 @@ const RULE_FILENAME: &str = "rule.toml"; /// The directory under the project root where the template cache lives. const CACHE_DIR_NAME: &str = "tmpl-cache"; -pack!(StateProjectGenerate = ()); -pack!(StateProjectChecklistReady = Vec<String>); +#[derive(Grouped)] +pub struct StateProjectGenerate; + +#[derive(Grouped, Wrap)] +pub struct StateProjectChecklistReady(Vec<String>); /// Result of the checklist phase: the extracted checklist handed to the user. #[derive(Debug, Default, Grouped)] @@ -46,20 +49,31 @@ pub struct ResultProjectGenerate { pub hidden: Vec<PathBuf>, } -pack_err!(ErrorTemplateNotProvided = ()); -pack_err!(ErrorTemplateCopyFailed = String); -pack_err!(ErrorTemplateFetchFailed = String); -pack_err!(ErrorChecklistMissing = String); -pack_err!(ErrorRuleParseFailed = String); -pack_err!(ErrorTemplateExpandFailed = String); +#[derive(Grouped)] +pub struct ErrorTemplateNotProvided; + +#[derive(Grouped, Wrap)] +pub struct ErrorTemplateCopyFailed(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorTemplateFetchFailed(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorChecklistMissing(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorRuleParseFailed(String); + +#[derive(Grouped, Wrap)] +pub struct ErrorTemplateExpandFailed(String); #[command(node = "proj-init", routeify)] pub fn proj_init(args: Entry, cwd: &ResCurrentDir) -> Next { // Check if the checklist.toml file exists in the current directory if cwd.join(CHECKLIST_FILENAME).exists() { - StateProjectGenerate::new(()).into() + StateProjectGenerate.into() } else { - StateProjectChecklistReady::new(args.inner).into() + StateProjectChecklistReady(args.0).into() } } @@ -73,7 +87,7 @@ pub fn handle_state_proj_checklist_ready( ) -> Next { let source: TemplateSource = args .pick_or_route(&arg![TemplateSource], || { - ErrorTemplateNotProvided::new(()).to_chain() + ErrorTemplateNotProvided.to_chain() }) .to_result()?; @@ -88,7 +102,7 @@ pub fn handle_state_proj_checklist_ready( configured }); resolve_git(&source_url, &reference, &variant, &cache_dir()) - .map_err(ErrorTemplateFetchFailed::new)? + .map_err(ErrorTemplateFetchFailed)? } }; @@ -96,15 +110,15 @@ pub fn handle_state_proj_checklist_ready( // directory; create it if it doesn't exist let tmpl_cache = cwd.join(".mling").join(CACHE_DIR_NAME); fs::create_dir_all(&tmpl_cache).map_err(|e| { - ErrorTemplateCopyFailed::new(format!("failed to create {}: {e}", tmpl_cache.display())) + ErrorTemplateCopyFailed(format!("failed to create {}: {e}", tmpl_cache.display())) })?; copy_dir_contents(&template_root, &tmpl_cache) - .map_err(|e| ErrorTemplateCopyFailed::new(e.to_string()))?; + .map_err(|e| ErrorTemplateCopyFailed(e.to_string()))?; // Move the internal checklist.toml to ./ for the user to fill in let checklist_src = tmpl_cache.join(CHECKLIST_FILENAME); if !checklist_src.is_file() { - return ErrorChecklistMissing::new(format!( + return ErrorChecklistMissing(format!( "no checklist.toml found inside {}", template_root.display() )) @@ -112,7 +126,7 @@ pub fn handle_state_proj_checklist_ready( } let checklist_dst = cwd.join(CHECKLIST_FILENAME); fs::rename(&checklist_src, &checklist_dst).map_err(|e| { - ErrorTemplateCopyFailed::new(format!( + ErrorTemplateCopyFailed(format!( "failed to move checklist.toml to {}: {e}", checklist_dst.display() )) @@ -130,7 +144,7 @@ pub fn handle_state_proj_checklist_ready( pub fn handle_state_project_generate(_: StateProjectGenerate, cwd: &ResCurrentDir) -> Next { let tmpl_cache = cwd.join(".mling").join(CACHE_DIR_NAME); if !tmpl_cache.is_dir() { - return ErrorChecklistMissing::new(format!( + return ErrorChecklistMissing(format!( "template cache not found at {}; run `mling proj-init` with a template directory first", tmpl_cache.display() )) @@ -140,22 +154,22 @@ pub fn handle_state_project_generate(_: StateProjectGenerate, cwd: &ResCurrentDi // Read the user-filled checklist.toml let checklist_path = cwd.join(CHECKLIST_FILENAME); let checklist_content = fs::read_to_string(&checklist_path).map_err(|e| { - ErrorChecklistMissing::new(format!("failed to read {}: {e}", checklist_path.display())) + ErrorChecklistMissing(format!("failed to read {}: {e}", checklist_path.display())) })?; let answers = parse_checklist(&checklist_content) - .map_err(|e| ErrorRuleParseFailed::new(format!("invalid checklist.toml: {e}")))?; + .map_err(|e| ErrorRuleParseFailed(format!("invalid checklist.toml: {e}")))?; // Read rule.toml (template rules) let rule_content = fs::read_to_string(tmpl_cache.join(RULE_FILENAME)) - .map_err(|e| ErrorRuleParseFailed::new(format!("failed to read rule.toml: {e}")))?; + .map_err(|e| ErrorRuleParseFailed(format!("failed to read rule.toml: {e}")))?; let rules = parse_rules(&rule_content) - .map_err(|e| ErrorRuleParseFailed::new(format!("invalid rule.toml: {e}")))?; + .map_err(|e| ErrorRuleParseFailed(format!("invalid rule.toml: {e}")))?; // Compute final answers from checklist values + defaults declared in rule.toml let answers = resolve_answers(&answers, &rules); // Mutually exclusive toggle groups must not both be enabled. - validate_mutexes(&answers, &rules).map_err(ErrorRuleParseFailed::new)?; + validate_mutexes(&answers, &rules).map_err(ErrorRuleParseFailed)?; // Derive the crate name from the program name (e.g. `my-cli` -> `my_cli`). let mut params: HashMap<String, String> = answers.clone(); @@ -171,7 +185,7 @@ pub fn handle_state_project_generate(_: StateProjectGenerate, cwd: &ResCurrentDi // Expand all template entries to the project root let mut generated = Vec::new(); expand_tree(&tmpl_cache, cwd, ¶ms, &mut generated, true) - .map_err(ErrorTemplateExpandFailed::new)?; + .map_err(ErrorTemplateExpandFailed)?; // hide-file: delete the corresponding generated file when the rule is true @@ -182,7 +196,7 @@ pub fn handle_state_project_generate(_: StateProjectGenerate, cwd: &ResCurrentDi } let target = cwd.join(hide.file.trim_start_matches("./")); remove_path(&target).map_err(|e| { - ErrorTemplateExpandFailed::new(format!("failed to hide {}: {e}", target.display())) + ErrorTemplateExpandFailed(format!("failed to hide {}: {e}", target.display())) })?; hidden.push(target); } @@ -194,19 +208,19 @@ pub fn handle_state_project_generate(_: StateProjectGenerate, cwd: &ResCurrentDi } let target = cwd.join(hide.dir.trim_start_matches("./")); remove_path(&target).map_err(|e| { - ErrorTemplateExpandFailed::new(format!("failed to hide {}: {e}", target.display())) + ErrorTemplateExpandFailed(format!("failed to hide {}: {e}", target.display())) })?; hidden.push(target); } // Clean up the cache fs::remove_dir_all(&tmpl_cache).map_err(|e| { - ErrorTemplateExpandFailed::new(format!("failed to remove {}: {e}", tmpl_cache.display())) + ErrorTemplateExpandFailed(format!("failed to remove {}: {e}", tmpl_cache.display())) })?; // Project generated; remove the temporary checklist file remove_path(&checklist_path).map_err(|e| { - ErrorTemplateExpandFailed::new(format!( + ErrorTemplateExpandFailed(format!( "failed to remove {}: {e}", checklist_path.display() )) @@ -327,35 +341,35 @@ pub fn render_error_template_not_provided(_err: ErrorTemplateNotProvided) -> Ren #[renderer] pub fn render_error_template_copy_failed(err: ErrorTemplateCopyFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "failed to copy template: {}", err.info); + eprintln_cargo!(r, "failed to copy template: {}", err.0); r } #[renderer] pub fn render_error_template_fetch_failed(err: ErrorTemplateFetchFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "failed to fetch template: {}", err.info); + eprintln_cargo!(r, "failed to fetch template: {}", err.0); r } #[renderer] pub fn render_error_checklist_missing(err: ErrorChecklistMissing) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_rule_parse_failed(err: ErrorRuleParseFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } #[renderer] pub fn render_error_template_expand_failed(err: ErrorTemplateExpandFailed) -> RenderResult { let mut r = RenderResult::new(); - eprintln_cargo!(r, "{}", err.info); + eprintln_cargo!(r, "{}", err.0); r } diff --git a/mingling_cli/src/updater.rs b/mingling_cli/src/updater.rs new file mode 100644 index 0000000..1c81fb3 --- /dev/null +++ b/mingling_cli/src/updater.rs @@ -0,0 +1 @@ +pub mod cmd_update; diff --git a/mingling_cli/src/updater/cmd_update.rs b/mingling_cli/src/updater/cmd_update.rs new file mode 100644 index 0000000..545361f --- /dev/null +++ b/mingling_cli/src/updater/cmd_update.rs @@ -0,0 +1,266 @@ +use std::{fs, path::Path, path::PathBuf}; + +use mingling::{ + Grouped, LazyRes, RenderResult, Routable, + macros::{chain, command, metadata, renderer, routeify}, + metadata::Description, +}; +use sha2::{Digest, Sha256}; + +use crate::{Next, config::ResMlingConfig, eprintln_cargo, println_cargo}; + +/// Config key holding the base URL that hosts the mling release packages. +const CONFIG_KEY_UPDATE_URL: &str = "update-url"; + +/// Default update source, used when the config key is unset. +const DEFAULT_UPDATE_URL: &str = "https://mingling-rs.github.io/mingling/dist"; + +/// Name of the staged update package inside `{data_dir}/mingling`. +const UPDATE_FILE_NAME: &str = "update.tar.gz"; + +/// Records the sha256 of the last applied update, written by the wrapper. +const LAST_UPDATE_FILE_NAME: &str = "last-update.sha256"; + +/// The resolved download task: check the remote checksum and stage the package. +#[derive(Debug, Default, Grouped)] +pub struct StateUpdateDownload { + pub base_url: String, + pub update_path: PathBuf, +} + +/// The latest package is already installed. +#[derive(Debug, Default, Grouped)] +pub struct ResultUpdateUpToDate; + +/// The latest package was downloaded, verified, and staged for the wrapper. +#[derive(Debug, Default, Grouped)] +pub struct ResultUpdateStaged { + pub update_path: PathBuf, +} + +/// Errors produced by the download pipeline. +#[derive(Debug, Grouped)] +pub enum UpdateError { + /// The data directory could not be determined. + NoDataDirectory, + /// The configured update URL is not a valid `http(s)://` URL. + InvalidUrl(String), + /// A network request failed, or the remote responded with an error. + Network(String), + /// The downloaded package failed its sha256 verification. + ChecksumMismatch(String), + /// Writing the staged update package failed. + Io(String), +} + +#[metadata(EntryUpdate)] +pub fn desc_update() -> Description { + "Update mling to the latest version".into() +} + +#[command(routeify)] +pub fn update(config: &mut LazyRes<ResMlingConfig>) -> Next { + let config = config.get_ref(); + let source = config.get_or(CONFIG_KEY_UPDATE_URL, DEFAULT_UPDATE_URL); + let Some(update_path) = update_package_path() else { + return UpdateError::NoDataDirectory.to_chain(); + }; + if !is_http_url(source) { + return UpdateError::InvalidUrl(source.to_string()).to_chain(); + } + StateUpdateDownload { + base_url: source.to_string(), + update_path, + } + .to_chain() +} + +/// Check the remote checksum against the installed version; if they differ, +/// download the package, verify its checksum, and stage it at +/// `{data_dir}/mingling/update.tar.gz`. +#[chain(routeify)] +pub async fn handle_state_update_download(state: StateUpdateDownload) -> Next { + match check_and_fetch(&state.base_url, &state.update_path).await { + Ok(FetchOutcome::UpToDate) => ResultUpdateUpToDate.to_chain(), + Ok(FetchOutcome::Staged) => ResultUpdateStaged { + update_path: state.update_path, + } + .to_chain(), + Err(e) => e.to_chain(), + } +} + +#[renderer] +pub fn render_result_update_up_to_date(_: ResultUpdateUpToDate) -> RenderResult { + let mut result = RenderResult::new(); + println_cargo!(result, "mling is already up to date"); + result +} + +#[renderer] +pub fn render_result_update_staged(r: ResultUpdateStaged) -> RenderResult { + let mut result = RenderResult::new(); + println_cargo!(result, "Downloaded: {}", r.update_path.display()); + println_cargo!(result, "Run `mling` again to apply the update"); + result +} + +#[renderer] +pub fn render_error_update(err: UpdateError) -> RenderResult { + let mut result = RenderResult::new(); + match err { + UpdateError::NoDataDirectory => { + eprintln_cargo!(result, "failed to determine the data directory"); + } + UpdateError::InvalidUrl(source) => { + eprintln_cargo!( + result, + "invalid update URL `{}`, expected an `http(s)://` URL such as `https://mingling-rs.github.io/mingling/dist`", + source + ); + } + UpdateError::Network(msg) | UpdateError::ChecksumMismatch(msg) | UpdateError::Io(msg) => { + eprintln_cargo!(result, "{}", msg); + } + } + result +} + +/// `{data_dir}/mingling/update.tar.gz`, where the wrapper looks for staged updates. +pub fn update_package_path() -> Option<PathBuf> { + dirs::data_dir().map(|dir| dir.join("mingling").join(UPDATE_FILE_NAME)) +} + +/// `{data_dir}/mingling/last-update.sha256`, the checksum of the last applied update. +fn last_update_checksum_path() -> Option<PathBuf> { + dirs::data_dir().map(|dir| dir.join("mingling").join(LAST_UPDATE_FILE_NAME)) +} + +fn is_http_url(source: &str) -> bool { + let source = source.trim(); + source.starts_with("http://") || source.starts_with("https://") +} + +/// The platform suffix used by the package names (`mling-{os}.tar.gz`). +fn update_os_name() -> &'static str { + if cfg!(windows) { + "win" + } else if cfg!(target_os = "linux") { + "linux" + } else if cfg!(target_os = "macos") { + "mac" + } else { + "unknown" + } +} + +enum FetchOutcome { + UpToDate, + Staged, +} + +/// Fetch `mling-{os}.tar.gz.sha256`, skip the download when the installed +/// version already matches, then download and verify the package before +/// staging it. +async fn check_and_fetch(base_url: &str, update_path: &Path) -> Result<FetchOutcome, UpdateError> { + let os = update_os_name(); + let base = base_url.trim_end_matches('/'); + let checksum_url = format!("{base}/mling-{os}.tar.gz.sha256"); + let package_url = format!("{base}/mling-{os}.tar.gz"); + + let client = reqwest::Client::builder() + .user_agent(format!("mling-updater/{}", env!("CARGO_PKG_VERSION"))) + .build() + .map_err(|e| UpdateError::Network(format!("failed to build HTTP client: {e}")))?; + + // 1. Fetch the remote checksum first. + let response = client.get(&checksum_url).send().await.map_err(|e| { + UpdateError::Network(format!( + "failed to fetch checksum from `{checksum_url}`: {e}" + )) + })?; + if !response.status().is_success() { + return Err(UpdateError::Network(format!( + "failed to fetch checksum from `{checksum_url}`: HTTP {}", + response.status() + ))); + } + let checksum_text = response + .text() + .await + .map_err(|e| UpdateError::Network(format!("failed to read checksum: {e}")))?; + let remote_sha = parse_sha256(&checksum_text).ok_or_else(|| { + UpdateError::Network(format!("invalid checksum file at `{checksum_url}`")) + })?; + + // 2. Skip the download when the installed version already matches. + if let Some(local_sha) = read_last_update_checksum() + && local_sha == remote_sha + { + return Ok(FetchOutcome::UpToDate); + } + + // 3. Download the package. + let response = + client.get(&package_url).send().await.map_err(|e| { + UpdateError::Network(format!("failed to download `{package_url}`: {e}")) + })?; + if !response.status().is_success() { + return Err(UpdateError::Network(format!( + "failed to download `{package_url}`: HTTP {}", + response.status() + ))); + } + let bytes = response + .bytes() + .await + .map_err(|e| UpdateError::Network(format!("failed to read package body: {e}")))?; + + // 4. Verify the package before staging it. + let actual_sha = sha256_hex(&bytes); + if actual_sha != remote_sha { + return Err(UpdateError::ChecksumMismatch(format!( + "checksum mismatch for `{package_url}`: expected {remote_sha}, got {actual_sha}" + ))); + } + + // 5. Stage it for the wrapper. + write_update_package(&bytes, update_path)?; + Ok(FetchOutcome::Staged) +} + +/// Parse the sha256 hex digest from a `sha256sum`-style line (`<hash> <file>`). +fn parse_sha256(line: &str) -> Option<String> { + let hash = line.split_whitespace().next()?; + (hash.len() == 64 && hash.chars().all(|c| c.is_ascii_hexdigit())).then(|| hash.to_string()) +} + +/// The checksum of the last update applied by the wrapper, if recorded. +fn read_last_update_checksum() -> Option<String> { + let path = last_update_checksum_path()?; + let content = fs::read_to_string(path).ok()?; + let sha = content.trim(); + (!sha.is_empty()).then(|| sha.to_string()) +} + +fn sha256_hex(bytes: &[u8]) -> String { + let mut hasher = Sha256::new(); + hasher.update(bytes); + format!("{:x}", hasher.finalize()) +} + +/// Stage the update package at the wrapper's well-known location. The bytes are +/// written to a temporary file first so a failed download never corrupts a +/// previously staged update. +fn write_update_package(package: &[u8], update_path: &Path) -> Result<(), UpdateError> { + let parent = update_path.parent().ok_or_else(|| { + UpdateError::Io(format!("no parent directory for {}", update_path.display())) + })?; + fs::create_dir_all(parent).map_err(|e| UpdateError::Io(e.to_string()))?; + let tmp_path = parent.join("update.tar.gz.tmp"); + fs::write(&tmp_path, package).map_err(|e| UpdateError::Io(e.to_string()))?; + if update_path.exists() { + fs::remove_file(update_path).map_err(|e| UpdateError::Io(e.to_string()))?; + } + fs::rename(&tmp_path, update_path).map_err(|e| UpdateError::Io(e.to_string())) +} |
