Add new command reset

[GitHub link #14] [Gitee link #I9V6EV]
This commit is contained in:
Aoran Zeng 2024-06-05 15:07:13 +08:00
parent b2cba6ca27
commit 6efe11a13c
2 changed files with 25 additions and 14 deletions

View File

@ -87,19 +87,22 @@ get <target> # 查看当前软件的源使用情况
set <target> # 换源,自动测速后挑选最快源 set <target> # 换源,自动测速后挑选最快源
set <target> first # 换源,使用维护团队测速第一的源 set <target> first # 换源,使用维护团队测速第一的源
set <target> <mirror> # 换源,指定使用某镜像站 (通过list命令查看) set <target> <mirror> # 换源,指定使用某镜像站 (通过list命令查看)
reset <target> # 重置,使用上游默认使用的源
选项: 选项:
-ipv6 # 使用IPv6测速 -ipv6 # 使用IPv6测速
-local # 仅对某项目而非全局换源 (仅部分软件如bundler,pdm支持) -local # 仅对某项目而非全局换源 (仅部分软件如bundler,pdm支持)
``` ```
当你不想自动测速的时候,你可以直接指定某镜像站。 当你**不想自动测速的时候**,你可以直接指定某镜像站,以及指定维护团队已测试的最快镜像站。
```bash ```bash
chsrc set ruby # 测速,寻找最快者,换源 chsrc set ruby # 测速,寻找最快者,换源
# 或 # 或
chsrc ls ruby # 列出可用的镜像站 chsrc ls ruby # 列出可用的镜像站
chsrc set ruby rubychina # 使用 RubyChina 作为镜像站 chsrc set ruby rubychina # 使用 RubyChina 作为镜像站
# 或
chsrc set ruby first # 使用维护团队测试的最快镜像站
``` ```
对部分[支持局部换源](https://gitee.com/RubyMetric/chsrc/issues/I9V5I0)的,可以避免全局换源。 对部分[支持局部换源](https://gitee.com/RubyMetric/chsrc/issues/I9V5I0)的,可以避免全局换源。

View File

@ -2093,7 +2093,8 @@ usage[] = {
"get <target> 查看当前软件的源使用情况", "get <target> 查看当前软件的源使用情况",
"set <target> 换源,自动测速后挑选最快源", "set <target> 换源,自动测速后挑选最快源",
"set <target> first 换源,使用维护团队测速第一的源", "set <target> first 换源,使用维护团队测速第一的源",
"set <target> <mirror> 换源,指定使用某镜像站 (通过list命令查看)\n", "set <target> <mirror> 换源,指定使用某镜像站 (通过list命令查看)",
"reset <target> 重置,使用上游默认使用的源\n"
"选项:", "选项:",
"-ipv6 使用IPv6测速", "-ipv6 使用IPv6测速",
@ -2101,18 +2102,6 @@ usage[] = {
}; };
void
call_cmd (void *cmdptr, const char *arg)
{
void (*cmd_func)(const char *) = cmdptr;
if (NULL==arg)
{
xy_info ("chsrc: 将使用默认镜像");
}
cmd_func (arg);
}
void void
print_available_mirrors () print_available_mirrors ()
@ -2501,6 +2490,25 @@ main (int argc, char const *argv[])
return 0; return 0;
} }
/* chsrc reset */
else if (xy_streql (command, "reset") ||
xy_streql (command, "rest") ||
xy_streql (command, "r"))
{
if (argc < cli_arg_Target_pos)
{
xy_error ("chsrc: 请您提供想要重置源的软件名; 使用 chsrc list targets 查看所有支持的软件");
return 1;
}
puts ("将重置并恢复上游默认使用的源");
target = argv[cli_arg_Target_pos];
char *mirror = "upstream";
matched = get_target (target, TargetOp_Set_Source, mirror);
if (!matched) goto not_matched;
return 0;
}
/* 不支持的命令 */ /* 不支持的命令 */
else else
{ {