From c1baed353628650ef0831b4440118bccd3212dd8 Mon Sep 17 00:00:00 2001 From: Fankai Liu Date: Wed, 29 Nov 2023 23:04:17 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8add=20feature=20=20check=20for=20updat?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 746 ++++++++++++++++++++++++++++++++- Cargo.toml | 2 + locales/cli_chek_updates.yml | 127 ++++++ src/main.rs | 7 +- src/utils/check_for_updates.rs | 49 +++ src/utils/mod.rs | 2 + src/utils/print_util.rs | 7 + 7 files changed, 932 insertions(+), 8 deletions(-) create mode 100644 locales/cli_chek_updates.yml create mode 100644 src/utils/check_for_updates.rs diff --git a/Cargo.lock b/Cargo.lock index 0033c49..649c29f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "1.1.1" @@ -80,7 +95,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -91,6 +106,27 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + [[package]] name = "bitflags" version = "1.3.2" @@ -122,6 +158,18 @@ dependencies = [ "serde", ] +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + [[package]] name = "cc" version = "1.0.83" @@ -212,6 +260,22 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" + [[package]] name = "cpufeatures" version = "0.2.9" @@ -265,6 +329,15 @@ version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +[[package]] +name = "encoding_rs" +version = "0.8.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +dependencies = [ + "cfg-if", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -304,6 +377,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -313,6 +401,45 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "futures-channel" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff4dd66668b557604244583e3e1e1eada8c5c2e96a6d0d6653ede395b78bbacb" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" + +[[package]] +name = "futures-sink" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817" + +[[package]] +name = "futures-task" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd193069b0ddadc69c46389b740bbccdd97203899b48d09c5f7969591d6bae2" + +[[package]] +name = "futures-util" +version = "0.3.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -323,6 +450,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "gimli" +version = "0.28.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" + [[package]] name = "git2" version = "0.18.1" @@ -368,6 +501,25 @@ dependencies = [ "walkdir", ] +[[package]] +name = "h2" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d6250322ef6e60f93f9a2162799302cd6f68f79f6e5d85c8c16f14d1d958178" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap 2.0.1", + "slab", + "tokio", + "tokio-util", + "tracing", +] + [[package]] name = "handlebars" version = "4.4.0" @@ -409,6 +561,83 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + +[[package]] +name = "http" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8947b1a6fad4393052c7ba1f4cd97bed3e953a95c79c92ad9b051a04611d9fbb" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "0.14.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2 0.4.10", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + [[package]] name = "idna" version = "0.4.0" @@ -456,6 +685,12 @@ dependencies = [ "hashbrown 0.14.0", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itertools" version = "0.10.5" @@ -489,6 +724,15 @@ dependencies = [ "libc", ] +[[package]] +name = "js-sys" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +dependencies = [ + "wasm-bindgen", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -497,9 +741,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.148" +version = "0.2.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libgit2-sys" @@ -553,6 +797,16 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" +[[package]] +name = "lock_api" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.20" @@ -565,6 +819,50 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.48.0", +] + +[[package]] +name = "native-tls" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "normpath" version = "1.1.1" @@ -574,12 +872,57 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "num_cpus" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +dependencies = [ + "hermit-abi 0.3.3", + "libc", +] + +[[package]] +name = "object" +version = "0.32.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "openssl" +version = "0.10.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79a4c6c3a2b158f7f8f2a2fc5a969fa3a068df6fc9dbb4a43845436e3af7c800" +dependencies = [ + "bitflags 2.4.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "openssl-probe" version = "0.1.5" @@ -588,9 +931,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.93" +version = "0.9.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d" +checksum = "3812c071ba60da8b5677cc12bcb1d42989a65553772897a7e0355545a819838f" dependencies = [ "cc", "libc", @@ -598,6 +941,29 @@ dependencies = [ "vcpkg", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "smallvec", + "windows-targets 0.48.5", +] + [[package]] name = "percent-encoding" version = "2.3.0" @@ -649,6 +1015,18 @@ dependencies = [ "sha2", ] +[[package]] +name = "pin-project-lite" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "pkg-config" version = "0.3.27" @@ -682,6 +1060,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "regex" version = "1.9.5" @@ -711,6 +1098,44 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" +[[package]] +name = "reqwest" +version = "0.11.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "046cd98826c46c2ac8ddecae268eb5c2e58628688a5fc7a2643704a73faba95b" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rust-i18n" version = "2.2.1" @@ -786,6 +1211,12 @@ dependencies = [ "toml", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustix" version = "0.38.13" @@ -816,9 +1247,11 @@ dependencies = [ "git2", "handlebars", "itertools 0.12.0", + "reqwest", "rust-i18n", "serde", "serde_json", + "tokio", "unicode-xid", ] @@ -831,6 +1264,44 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "schannel" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c3733bf4cf7ea0880754e19cb5a462007c4a8c1914bff372ccc95b464f1df88" +dependencies = [ + "windows-sys 0.48.0", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "2.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b64fb303737d99b81884b2c63433e9ae28abebe5eb5045dcdd175dc2ecf4de" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e932934257d3b408ed8f30db49d85ea163bfe74961f017f405b025af298f0c7a" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "serde" version = "1.0.188" @@ -871,6 +1342,18 @@ dependencies = [ "serde", ] +[[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 = "serde_yaml" version = "0.8.26" @@ -900,6 +1383,50 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + +[[package]] +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dccd0940a2dcdf68d092b8cbab7dc0ad8fa938bf95787e1b916b0e3d0e8e970" + +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "socket2" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +dependencies = [ + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "strsim" version = "0.8.0" @@ -923,6 +1450,27 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tempfile" version = "3.8.0" @@ -931,7 +1479,7 @@ checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" dependencies = [ "cfg-if", "fastrand", - "redox_syscall", + "redox_syscall 0.3.5", "rustix", "windows-sys 0.48.0", ] @@ -990,6 +1538,60 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "tokio" +version = "1.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0c014766411e834f7af5b8f4cf46257aab4036ca95e9d2c144a10f59ad6f5b9" +dependencies = [ + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2 0.5.5", + "tokio-macros", + "windows-sys 0.48.0", +] + +[[package]] +name = "tokio-macros" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + [[package]] name = "toml" version = "0.7.8" @@ -1024,6 +1626,37 @@ dependencies = [ "winnow", ] +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" + [[package]] name = "typenum" version = "1.17.0" @@ -1114,6 +1747,97 @@ dependencies = [ "winapi-util", ] +[[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.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" + +[[package]] +name = "web-sys" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50c24a44ec86bb68fbecd1b3efed7e85ea5621b39b35ef2766b66cd984f8010f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "winapi" version = "0.3.9" @@ -1286,6 +2010,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "yaml-rust" version = "0.4.5" diff --git a/Cargo.toml b/Cargo.toml index 17bfc2b..eb9b5d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,3 +25,5 @@ serde_json = "1.0.107" unicode-xid = "0.2.4" rust-i18n = "2" itertools = "0.12.0" +reqwest = "0.11.22" +tokio = { version = "1", features = ["full"] } \ No newline at end of file diff --git a/locales/cli_chek_updates.yml b/locales/cli_chek_updates.yml new file mode 100644 index 0000000..d7c7ce8 --- /dev/null +++ b/locales/cli_chek_updates.yml @@ -0,0 +1,127 @@ +_version: 2 +checking_for_updates: + en: Checking for updates... + zh_CN: 正在检查更新... + zh_TW: 正在檢查更新... + fr: Vérification des mises à jour... + ja: 更新を確認しています... + es: Comprobando actualizaciones... + de: Suche nach Updates... + ru: Проверка обновлений... + it: Verifica degli aggiornamenti... + pt: Verificando atualizações... + ko: 업데이트를 확인하는 중... + no: Sjekker for oppdateringer... + is: Athuga með uppfærslur... + uk: Перевірка оновлень... + th: กำลังตรวจสอบการอัปเดต... + el: Έλεγχος για ενημερώσεις... + da: Kontrollerer for opdateringer... +new_version_available: + en: A new version of salvo-cli is available `%{latest_version}` + zh_CN: 可用新版本的salvo-cli `%{latest_version}` + zh_TW: 可用新版本的salvo-cli `%{latest_version}` + fr: Une nouvelle version de salvo-cli est disponible `%{latest_version}` + ja: salvo-cliの新しいバージョンが利用可能です `%{latest_version}` + es: Está disponible una nueva versión de salvo-cli `%{latest_version}` + de: Eine neue Version von salvo-cli ist verfügbar `%{latest_version}` + ru: Доступна новая версия salvo-cli `%{latest_version}` + it: È disponibile una nuova versione di salvo-cli `%{latest_version}` + pt: Uma nova versão do salvo-cli está disponível `%{latest_version}` + ko: salvo-cli의 새 버전을 사용할 수 있습니다 `%{latest_version}` + no: En ny versjon av salvo-cli er tilgjengelig `%{latest_version}` + is: Ný útgáfa af salvo-cli er tiltæk `%{latest_version}` + uk: Доступна нова версія salvo-cli `%{latest_version}` + th: มีรุ่นใหม่ของ salvo-cli ที่ใช้ได้ `%{latest_version}` + el: Μια νέα έκδοση του salvo-cli είναι διαθέσιμη `%{latest_version}` + da: En ny version af salvo-cli er tilgængelig `%{latest_version}` +currently_using_version: + en: You are currently using version `%{current_version}` + zh_CN: 您当前正在使用版本 `%{current_version}` + zh_TW: 您目前正在使用版本 `%{current_version}` + fr: Vous utilisez actuellement la version `%{current_version}` + ja: 現在使用しているバージョンは `%{current_version}` + es: Actualmente estás usando la versión `%{current_version}` + de: Sie verwenden derzeit die Version `%{current_version}` + ru: В настоящее время вы используете версию `%{current_version}` + it: Stai attualmente utilizzando la versione `%{current_version}` + pt: Você está atualmente usando a versão `%{current_version}` + ko: 현재 사용 중인 버전은 `%{current_version}` + no: Du bruker for øyeblikket versjon `%{current_version}` + is: Þú ert núna að nota útgáfu `%{current_version}` + uk: Ви використовуєте версію `%{current_version}` + th: คุณกำลังใช้เวอร์ชัน `%{current_version}` + el: Χρησιμοποιείτε την έκδοση `%{current_version}` + da: Du bruger i øjeblikket version `%{current_version}` +consider_updating: + en: Consider updating by running:cargo install --force salvo-cli + zh_CN: 考虑运行以下命令进行更新:cargo install --force salvo-cli + zh_TW: 考慮執行以下指令進行更新:cargo install --force salvo-cli + fr: Envisagez de mettre à jour en exécutant :cargo install --force salvo-cli + ja: 更新を検討してください:cargo install --force salvo-cliを実行 + es: Considera la actualización ejecutando:cargo install --force salvo-cli + de: Überlegen Sie, ein Update durchzuführen:cargo install --force salvo-cli + ru: Рассмотрите возможность обновления, выполнив:cargo install --force salvo-cli + it: Considera di aggiornare eseguendo:cargo install --force salvo-cli + pt: Considere atualizar executando:cargo install --force salvo-cli + ko: 다음을 실행하여 업데이트를 고려하십시오:cargo install --force salvo-cli + no: Vurder å oppdatere ved å kjøre:cargo install --force salvo-cli + is: Íhugaðu að uppfæra með því að keyra:cargo install --force salvo-cli + uk: Розгляньте можливість оновлення, запустивши:cargo install --force salvo-cli + th: พิจารณาการอัปเดตโดยการเรียกใช้:cargo install --force salvo-cli + el: Σκεφτείτε να ενημερώσετε εκτελώντας:cargo install --force salvo-cli + da: Overvej at opdatere ved at køre:cargo install --force salvo-cli +unable_to_verify_updates: + en: Unable to verify updates at this moment + zh_CN: 当前无法验证更新 + zh_TW: 目前無法驗證更新 + fr: Impossible de vérifier les mises à jour pour le moment + ja: 現在、更新を確認できません + es: No se pueden verificar las actualizaciones en este momento + de: Derzeit können keine Updates überprüft werden + ru: Невозможно проверить обновления в данный момент + it: Impossibile verificare gli aggiornamenti al momento + pt: Não é possível verificar atualizações neste momento + ko: 현재 업데이트를 확인할 수 없습니다 + no: Kan ikke bekrefte oppdateringer for øyeblikket + is: Ekki hægt að staðfesta uppfærslur í augnablikinu + uk: Неможливо перевірити оновлення на даний момент + th: ไม่สามารถตรวจสอบการอัปเดตในขณะนี้ + el: Αδυναμία επαλήθευσης των ενημερώσεων αυτή τη στιγμή + da: Kan ikke bekræfte opdateringer i øjeblikket +update_verification_took_long: + en: The update verification process took longer than expected + zh_CN: 更新验证过程用时超过预期 + zh_TW: 更新驗證過程所花時間超過預期 + fr: Le processus de vérification des mises à jour a pris plus de temps que prévu + ja: アップデートの確認プロセスが予想以上に時間がかかりました + es: El proceso de verificación de actualizaciones tardó más de lo esperado + de: Der Aktualisierungsüberprüfungsprozess dauerte länger als erwartet + ru: Процесс проверки обновлений занял больше времени, чем ожидалось + it: Il processo di verifica dell'aggiornamento ha richiesto più tempo del previsto + pt: O processo de verificação de atualizações demorou mais do que o esperado + ko: 업데이트 확인 과정이 예상보다 오래 걸렸습니다 + no: Oppdateringsverifikasjonsprosessen tok lenger tid enn forventet + is: Uppflettitferlinn tók lengri tíma en gera mátti ráð fyrir + uk: Процес перевірки оновлень зайняв більше часу, ніж очікувалося + th: กระบวนการตรวจสอบการอัปเดตใช้เวลานานกว่าที่คาดหวัง + el: Η διαδικασία επαλήθευσης των ενημερώσεων πήρε περισσότερο χρόνο από ό,τι αναμενόταν + da: Opdateringsbekræftelsesprocessen tog længere tid end forventet +current_version_up_to_date: + en: The current version is up to date + zh_CN: 当前已经是最新版本 + zh_TW: 目前已經是最新版本 + fr: La version actuelle est à jour + ja: 現在のバージョンは最新です + es: La versión actual está actualizada + de: Die aktuelle Version ist auf dem neuesten Stand + ru: Текущая версия обновлена + it: La versione corrente è aggiornata + pt: A versão atual está atualizada + ko: 현재 버전이 최신입니다 + no: Den nåværende versjonen er oppdatert + is: Núverandi útgáfa er uppfærð + uk: Поточна версія оновлена + th: รุ่นปัจจุบันเป็นรุ่นล่าสุด + el: Η τρέχουσα έκδοση είναι ενημερωμένη + da: Den nuværende version er opdateret \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5118ba2..1cf673d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,10 +3,11 @@ use clap::Parser; mod test; mod utils; use i18n::set_locale; +use utils::check_for_updates; mod i18n; rust_i18n::i18n!("locales", fallback = "en"); #[derive(Parser, Debug)] -#[clap(version = "0.1.26", author = "Fankai liu ")] +#[clap(version = env!("CARGO_PKG_VERSION"), author = "Fankai liu ")] struct Opts { #[clap(subcommand)] subcmd: SubCommand, @@ -22,12 +23,14 @@ pub struct Project { #[clap(short, long)] lang: Option, } -fn main() -> Result<()> { +#[tokio::main] +async fn main() -> Result<()> { utils::print_logo(); let opts: Opts = Opts::parse(); match opts.subcmd { SubCommand::New(project) => { set_locale(&project.lang); + check_for_updates().await; match utils::create_project(project) { Ok(_) => (), Err(e) => utils::error(e.to_string()), diff --git a/src/utils/check_for_updates.rs b/src/utils/check_for_updates.rs new file mode 100644 index 0000000..7aae760 --- /dev/null +++ b/src/utils/check_for_updates.rs @@ -0,0 +1,49 @@ +use crate::utils::{print_util::orange, success, warning}; +use rust_i18n::t; +use serde_json::Value; +use std::time::Duration; +use tokio::time::timeout; + +use super::print_util::green; + +async fn get_latest_version(crate_name: &str) -> Result> { + let url = format!("https://crates.io/api/v1/crates/{}", crate_name); + let client = reqwest::Client::builder() + .user_agent("salvo-cli update checker") + .build()?; + let resp = client.get(&url).send().await?; + let body: String = resp.text().await?; + let crate_response: Value = serde_json::from_str(&body)?; + let latest_version = crate_response["crate"]["max_version"] + .as_str() + .ok_or("Failed to get max_version")? + .to_string(); + Ok(latest_version) +} + +pub async fn check_for_updates() { + success(t!("checking_for_updates")); + let result = timeout(Duration::from_secs(3), get_latest_version("salvo-cli")).await; + + match result { + Ok(Ok(latest_version)) => { + let current_version = env!("CARGO_PKG_VERSION"); + if latest_version != current_version { + orange(t!("new_version_available", latest_version = latest_version)); + orange(t!( + "currently_using_version", + current_version = current_version + )); + orange(t!("consider_updating")); + } else { + green(t!("current_version_up_to_date")); + } + } + Ok(Err(e)) => { + warning(format!("{},{}", t!("unable_to_verify_updates"), e)); + } + Err(_) => { + warning(t!("update_verification_took_long")); + } + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 983ff57..022fee9 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,6 +1,8 @@ +mod check_for_updates; pub mod create_project; pub mod get_selection; mod print_util; mod restricted_names; +pub use check_for_updates::check_for_updates; pub use create_project::create_project; pub use print_util::{error, print_logo, success, warning}; diff --git a/src/utils/print_util.rs b/src/utils/print_util.rs index 9faf894..31ceded 100644 --- a/src/utils/print_util.rs +++ b/src/utils/print_util.rs @@ -1,3 +1,4 @@ +use ansi_term::Colour; use ansi_term::Colour::{Blue, Green, Red, Yellow}; pub fn print_logo() { @@ -26,3 +27,9 @@ pub fn error>(msg: S) { pub fn success>(msg: S) { println!("{}", Blue.paint(msg.as_ref())); } +pub fn orange>(msg: S) { + println!("{}", Colour::RGB(255, 165, 0).paint(msg.as_ref())); +} +pub fn green>(msg: S) { + println!("{}", Green.paint(msg.as_ref())); +}