Skip to content

Commit

Permalink
Merge branch 'main' of github.com:wtklbm/crm
Browse files Browse the repository at this point in the history
  • Loading branch information
wtklbm committed Nov 23, 2023
2 parents 2aa4ce1 + 9aea8c5 commit b5c7c24
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"cwd": "${workspaceRoot}",
"program": "${workspaceRoot}/target/debug/${workspaceFolderBasename}",
"preLaunchTask": "Rust: 构建开发版本",
"args": ["list"],
"env": {
"RUST_BACKTRACE": "full"
}
Expand All @@ -20,6 +21,7 @@
"valuesFormatting": "parseText",
"target": "./target/debug/${workspaceFolderBasename}.exe",
"preLaunchTask": "Rust: 构建开发版本",
"arguments": "list",
"env": {
"RUST_BACKTRACE": "full"
}
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "crm"
version = "0.2.0"
version = "0.2.1"
authors = ["wtklbm <wtklbm@gmail.com>"]
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"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ lazy_static = {version = "1.4.0", registry = "sjtu"}



> NOTE:如果您刚安装 `crm`,那么请在终端执行一次:`crm default`,然后就可以在项目的 `Cargo.toml` 文件中配置 `registry` 属性了。
> NOTE:
> - 如果您刚安装 `crm`,那么请在终端执行一次:`crm default`,然后就可以在项目的 `Cargo.toml` 文件中配置 `registry` 属性了。
> - 从 Rust v1.39.0 版本开始,`~/.cargo/config.toml` 将被推荐使用,如果 `~/.cargo/config``~/.cargo/config.toml` 同时存在,则优先使用 `~/.cargo/config` 配置。


Expand Down
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub const DOT_CARGO: &str = ".cargo";
/// `${CARGO_HOME}/.cargo` 目录下的 `config` 文件
pub const CONFIG: &str = "config";

/// `${CARGO_HOME}/.cargo` 目录下的 `config.toml` 文件 (推荐)
pub const CONFIG_TOML: &str = "config.toml";

/// `dl`
pub const DL: &str = "dl";

Expand Down
11 changes: 10 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::{

use ureq::Error;

use crate::constants::{CARGO_CONFIG_PATH, CARGO_HOME, CONFIG, DOT_CARGO, UNC_PREFIX};
use crate::constants::{CARGO_CONFIG_PATH, CARGO_HOME, CONFIG, CONFIG_TOML, DOT_CARGO, UNC_PREFIX};

pub fn home_dir() -> PathBuf {
env::home_dir().unwrap()
Expand All @@ -34,8 +34,17 @@ pub fn cargo_home() -> PathBuf {

pub fn cargo_config_path() -> PathBuf {
let mut c = cargo_home();

// Cargo 还读取不带 `.toml` 扩展名的配置文件,例如 `~/.cargo/config`
// 如果该文件存在,Cargo 将首先使用不带扩展名的文件
// https://doc.rust-lang.org/cargo/reference/config.html
c.push(CONFIG);

// Rust v1.39 版本中添加了对该 `.toml` 扩展的支持,并且是首选形式
if !c.exists() {
c.set_file_name(CONFIG_TOML);
}

c
}

Expand Down

0 comments on commit b5c7c24

Please sign in to comment.