feat(cargo): 实现cargo自动换源

参考 uv 换源实现

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
happygame
2025-09-13 10:13:35 +08:00
committed by 曾奥然
parent d71ea423dd
commit 885bb5103b
3 changed files with 81 additions and 7 deletions

View File

@@ -3,9 +3,9 @@
! -------------------------------------------------------------
! Config Type : rawstr4c (Markdown)
! Config Authors: Aoran Zeng <ccmywish@qq.com>
! Contributors : Nil Null <nil@null.org>
! Contributors : Happy Game <happygame1024@gmail.com>
! Created On : <2025-07-14>
! Last Modified : <2025-08-08>
! Last Modified : <2025-09-13>
! ---------------------------------------------------------- -->
# rawstr4c input for PL
@@ -81,6 +81,30 @@ replace-with = 'mirror'
registry = "sparse+@url@"
```
### cargo check config
- name = `cargo_check_config`
```bash
grep -q '^\[source\.crates-io\]' @f@
```
### cargo update replace-with
- name = `cargo_update_replace_with`
```bash
@sed@ '/^\[source\.crates-io\]$/,/^\[/{s/^replace-with = .*/replace-with = "mirror"/}' @f@
```
### cargo update registry
- name = `cargo_update_registry`
```bash
@sed@ '/^\[source\.mirror\]$/,/^\[/{s|^registry = .*|registry = "sparse+@url@"|}' @f@
```
<br>