From 937f4e724ef266b0af7900a1fea98de7f287e1a0 Mon Sep 17 00:00:00 2001 From: LinkChou Date: Tue, 27 Aug 2024 21:46:52 +0800 Subject: [PATCH 1/2] chore: format code with clippy tips and add version --- Cargo.toml | 26 +++++++++++++------------- src/args.rs | 17 +++++++---------- src/cargo.rs | 4 +--- src/runtime.rs | 6 +++++- src/utils.rs | 9 ++++++--- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 27c2642..6364a5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,20 +1,20 @@ [package] -name = "crm" -version = "0.2.1" -authors = ["wtklbm "] +name = "crm" +version = "0.2.2" +authors = ["wtklbm "] description = "crm can help you easy and fast switch between different cargo registries, now include: sjtu, tuna, ustc, rsproxy, bfsu, nju, hit." -homepage = "https://github.com/wtklbm/crm" -repository = "https://github.com/wtklbm/crm.git" -edition = "2018" -license = "MIT OR Apache-2.0" -keywords = ["cargo", "registry"] -exclude = [".vscode/**"] +homepage = "https://github.com/wtklbm/crm" +repository = "https://github.com/wtklbm/crm.git" +edition = "2018" +license = "MIT OR Apache-2.0" +keywords = ["cargo", "registry"] +exclude = [".vscode/**"] [profile.release] codegen-units = 1 -opt-level = "z" -panic = "abort" -strip = true +opt-level = "z" +panic = "abort" +strip = true #lto = "fat" [profile.dev] @@ -22,4 +22,4 @@ codegen-units = 512 [dependencies] toml_edit = "0.2.1" -ureq = "2.1.1" +ureq = "2.1.1" diff --git a/src/args.rs b/src/args.rs index 473df5b..741cb25 100644 --- a/src/args.rs +++ b/src/args.rs @@ -74,10 +74,10 @@ pub fn handle_command((command, args): Args) { "default" => r.default(), // 切换镜像 - "use" => r.select(args.get(0)), + "use" => r.select(args.first()), // 删除镜像 - "remove" => r.remove(args.get(0)), + "remove" => r.remove(args.first()), // 使用官方镜像执行 `cargo publish` "publish" => r.publish(args.join(" ")), @@ -89,7 +89,7 @@ pub fn handle_command((command, args): Args) { "install" => r.install(args.join(" ")), // 对镜像源网络延迟进行评估 - "test" => r.test(&r.current().0, args.get(0)), + "test" => r.test(&r.current().0, args.first()), // 获取当前镜像 "current" => { @@ -108,20 +108,17 @@ pub fn handle_command((command, args): Args) { // 检查版本更新 "check-update" => { - match get_newest_version() { - Some(newest) => { - if newest != APP_VERSION { - return println!(" 检测到新版本: {newest},请切换到官方镜像源以执行更新"); - } + if let Some(newest) = get_newest_version() { + if newest != APP_VERSION { + return println!(" 检测到新版本: {newest},请切换到官方镜像源以执行更新"); } - None => {} }; println!(" 暂无更新"); } command => { - let name = args.get(0); + let name = args.first(); let addr = args.get(1); let dl = args.get(2); diff --git a/src/cargo.rs b/src/cargo.rs index cef3173..d8d194b 100644 --- a/src/cargo.rs +++ b/src/cargo.rs @@ -122,9 +122,7 @@ impl CargoConfig { }; // 从配置文件中根据镜像名获取镜像地址 - let addr = data[SOURCE][name][REGISTRY] - .as_str() - .map(|v| v.to_string()); + let addr = data[SOURCE][name][REGISTRY].as_str().map(|v| v.to_string()); (name.to_string(), addr) } diff --git a/src/runtime.rs b/src/runtime.rs index 9c228e0..0496f60 100644 --- a/src/runtime.rs +++ b/src/runtime.rs @@ -72,7 +72,11 @@ impl RuntimeConfig { /// 将运行时配置中的镜像列表转换为字符串 pub fn to_string(&self, current: &String, sep: Option<&str>) -> String { - let sep = if sep.is_none() { "" } else { Option::unwrap(sep) }; + let sep = if sep.is_none() { + "" + } else { + Option::unwrap(sep) + }; self.iter() .fold(String::new(), |mut memo, (k, v)| { diff --git a/src/utils.rs b/src/utils.rs index 4ff70a9..19a154d 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,7 +8,7 @@ use std::{ env, ffi::OsStr, fmt::Display, - fs::{rename, read_to_string}, + fs::{read_to_string, rename}, io, path::{Path, PathBuf}, process::{self, Command, Output, Stdio}, @@ -49,7 +49,10 @@ pub fn cargo_config_path() -> PathBuf { process::exit(20); } } else if obsolete_path.is_file() { - to_out(format!("检测到了 {:?} 配置文件 (不再被推荐使用),以后请使用 {:?} 配置文件", obsolete_path, path)); + to_out(format!( + "检测到了 {:?} 配置文件 (不再被推荐使用),以后请使用 {:?} 配置文件", + obsolete_path, path + )); rename(obsolete_path, &path).unwrap(); } @@ -245,7 +248,7 @@ pub fn exec_command(command: &str, cwd: Option<&String>) -> io::Result { Command::new(program) .current_dir(cwd) - .args(&[arg_c, command]) + .args([arg_c, command]) .stdin(Stdio::inherit()) .stdout(Stdio::inherit()) .stderr(Stdio::inherit()) From 44d162001a29c8406b2add47c3ead6e05df03129 Mon Sep 17 00:00:00 2001 From: LinkChou Date: Tue, 27 Aug 2024 21:50:22 +0800 Subject: [PATCH 2/2] feature: add mirrors --- Cargo.toml | 2 +- src/constants.rs | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6364a5f..0d13c77 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "crm" version = "0.2.2" authors = ["wtklbm "] -description = "crm can help you easy and fast switch between different cargo registries, now include: sjtu, tuna, ustc, rsproxy, bfsu, nju, hit." +description = "crm can help you easy and fast switch between different cargo registries, now include: sjtu, tuna, ustc, rsproxy, bfsu, nju, hit, cqu, zju, CERNET." homepage = "https://github.com/wtklbm/crm" repository = "https://github.com/wtklbm/crm.git" edition = "2018" diff --git a/src/constants.rs b/src/constants.rs index 3401079..ae6e686 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -147,4 +147,24 @@ dl = "https://crates.io/api/v1/crates" [source.hit] registry = "https://mirrors.hit.edu.cn/crates.io-index.git" dl = "https://crates.io/api/v1/crates" + +# 重庆大学 - sparse +[source.cqu-sparse] +registry = "sparse+https://mirrors.cqu.edu.cn/crates.io-index/" +dl = "https://crates.io/api/v1/crates" + +# 浙江大学 - sparse +[source.zju-sparse] +registry = "sparse+https://mirrors.zju.edu.cn/crates.io-index/" +dl = "https://crates.io/api/v1/crates" + +# CERNET聚合镜像 +[source.cernet] +registry = "https://mirrors.cernet.edu.cn/crates.io-index.git" +dl = "https://crates.io/api/v1/crates" + +# CERNET聚合镜像 - sparse +[source.cernet-sparse] +registry = "sparse+https://mirrors.cernet.edu.cn/crates.io-index/" +dl = "https://crates.io/api/v1/crates" "#;