From 0b5efcb77ded08f0be5838987067236e19d2c713 Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Sun, 22 Feb 2026 21:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E9=83=A8=E4=BD=BF=E7=94=A8=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81=E5=8F=98=E9=87=8F=E5=88=A4=E6=96=AD?= =?UTF-8?q?scope?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chsrc-main.c | 17 ++++++++--------- src/framework/core.c | 3 --- src/recipe/lang/Clojure.c | 2 +- src/recipe/lang/JavaScript/Bun.c | 2 +- src/recipe/lang/JavaScript/Yarn.c | 4 ++-- src/recipe/lang/JavaScript/npm.c | 2 +- src/recipe/lang/JavaScript/pnpm.c | 2 +- src/recipe/lang/PHP.c | 2 +- src/recipe/lang/Python/PDM.c | 2 +- src/recipe/lang/Python/Poetry.c | 2 +- src/recipe/lang/Python/pip.c | 2 +- src/recipe/lang/Python/uv.c | 2 +- src/recipe/lang/Ruby/Ruby.c | 2 +- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/chsrc-main.c b/src/chsrc-main.c index b3870a2..84c30b6 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -303,19 +303,20 @@ cli_print_target_features (Target_t *target, const char *input_target_name) } { - char *msg = ENGLISH ? " Locally: Change source only for this project " : " Locally: 仅对本项目换源 "; - char *locally_msg = xy_strcat (3, msg, "| chsrc set -local ", input_target_name); + char *msg = CHINESE ? " Scope: 换源作用域 " + : " Scope: scope of the recipe"; + char *scope_msg = xy_strcat (3, msg, "| chsrc set -scope=default|project|user|system ", input_target_name); switch (target->cap_local) { case CanNot: - printf (" %s%s\n", bdred(NoMark), locally_msg);br(); + printf (" %s%s\n", bdred(NoMark), scope_msg);br(); break; case FullyCan: - printf (" %s%s\n", bdgreen(YesMark), purple(locally_msg));br(); + printf (" %s%s\n", bdgreen(YesMark), purple(scope_msg));br(); break; case PartiallyCan: - printf (" %s%s\n\n %s\n", bdgreen(HalfYesMark), purple(locally_msg), + printf (" %s%s\n\n %s\n", bdgreen(HalfYesMark), purple(scope_msg), target->cap_local_explain ? target->cap_local_explain : "");br(); break; default: @@ -744,11 +745,10 @@ main (int argc, char const *argv[]) } else if (xy_streql (argv[i], "-local")) { - ProgMode.LocalMode = true; + ProgMode.Scope = ProjectScope; char *msg = CHINESE ? " -local 选项已弃用,请使用 -scope=project" : " -local is deprecated, please use -scope=project"; - chsrc_error (msg); - return Exit_Unsupported; + chsrc_warn (msg); } else if (xy_str_start_with (argv[i], "-scope")) { @@ -766,7 +766,6 @@ main (int argc, char const *argv[]) if (xy_streql_ic (scope, "project")) { ProgMode.Scope = ProjectScope; - ProgMode.LocalMode = true; /* 迁移过程中,暂时使用原有的 LocalMode 来实现 */ } else if (xy_streql_ic (scope, "user")) { diff --git a/src/framework/core.c b/src/framework/core.c index c81f2dd..43f53be 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -46,7 +46,6 @@ struct // 用户命令选项 bool Ipv6Mode; - bool LocalMode; Scope_t Scope; bool EnglishMode; bool DryRunMode; @@ -58,7 +57,6 @@ ProgMode = .ResetMode = false, .TargetGroupMode = false, .Ipv6Mode = false, - .LocalMode = false, .Scope = DefaultScope, .EnglishMode = false, .DryRunMode = false, @@ -72,7 +70,6 @@ bool chsrc_in_standalone_mode() {return !ProgMode.TargetGroupMode;} void chsrc_set_target_group_mode(){ProgMode.TargetGroupMode = true;} bool chsrc_in_reset_mode(){return ProgMode.ResetMode;} -bool chsrc_in_local_mode(){return ProgMode.LocalMode;} bool chsrc_in_default_scope_mode(){return ProgMode.Scope == DefaultScope;} bool chsrc_in_user_scope_mode(){return ProgMode.Scope == UserScope;} bool chsrc_in_project_scope_mode(){return ProgMode.Scope == ProjectScope;} diff --git a/src/recipe/lang/Clojure.c b/src/recipe/lang/Clojure.c index aa345c6..3e3ed86 100644 --- a/src/recipe/lang/Clojure.c +++ b/src/recipe/lang/Clojure.c @@ -38,7 +38,7 @@ pl_clojure_setsrc (char *option) { chsrc_use_this_source (pl_clojure); - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { chsrc_note2 ("请在项目根目录中的 project.clj 中手动添加 :mirrors 关键字:"); char *config = xy_str_gsub (RAWSTR_pl_clojure_project_clj, "@url@", source.url); diff --git a/src/recipe/lang/JavaScript/Bun.c b/src/recipe/lang/JavaScript/Bun.c index bf3d3a9..f79cc8b 100644 --- a/src/recipe/lang/JavaScript/Bun.c +++ b/src/recipe/lang/JavaScript/Bun.c @@ -51,7 +51,7 @@ pl_js_bun_setsrc (char *option) content = xy_str_gsub (content, "@url@", source.url); - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { chsrc_note2 ("请手动写入以下内容到本项目根目录的 bunfig.toml 文件中"); } diff --git a/src/recipe/lang/JavaScript/Yarn.c b/src/recipe/lang/JavaScript/Yarn.c index dd29bb9..50c1ded 100644 --- a/src/recipe/lang/JavaScript/Yarn.c +++ b/src/recipe/lang/JavaScript/Yarn.c @@ -62,7 +62,7 @@ pl_js_yarn_setsrc (char *option) // 从 Yarn V2 开始,使用新的配置名 if (pl_js_yarn_get_yarn_version () >= 2) { - if (chsrc_in_local_mode()) // Yarn 默认情况下就是基于本项目换源 + if (chsrc_in_project_scope_mode()) // Yarn 默认情况下就是基于本项目换源 cmd = xy_2strcat ("yarn config set npmRegistryServer ", source.url); else cmd = xy_2strcat ("yarn config set npmRegistryServer --home ", source.url); @@ -71,7 +71,7 @@ pl_js_yarn_setsrc (char *option) } else { - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { char *msg = ENGLISH ? "Yarn v1 doesn't support `-local`. SKIP changing source!" : "Yarn v1 不支持 -local,跳过换源"; chsrc_error (msg); diff --git a/src/recipe/lang/JavaScript/npm.c b/src/recipe/lang/JavaScript/npm.c index c359ddf..a7eddc9 100644 --- a/src/recipe/lang/JavaScript/npm.c +++ b/src/recipe/lang/JavaScript/npm.c @@ -44,7 +44,7 @@ pl_js_npm_setsrc (char *option) char *cmd = NULL; - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) cmd = xy_2strcat ("npm config --location project set registry ", source.url); else cmd = xy_2strcat ("npm config set registry ", source.url); diff --git a/src/recipe/lang/JavaScript/pnpm.c b/src/recipe/lang/JavaScript/pnpm.c index 42577ba..345f4dc 100644 --- a/src/recipe/lang/JavaScript/pnpm.c +++ b/src/recipe/lang/JavaScript/pnpm.c @@ -45,7 +45,7 @@ pl_js_pnpm_setsrc (char *option) char *cmd = NULL; - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) cmd = xy_2strcat ("pnpm config --location project set registry ", source.url); else cmd = xy_2strcat ("pnpm config -g set registry ", source.url); diff --git a/src/recipe/lang/PHP.c b/src/recipe/lang/PHP.c index 4cdfade..093908e 100644 --- a/src/recipe/lang/PHP.c +++ b/src/recipe/lang/PHP.c @@ -58,7 +58,7 @@ pl_php_setsrc (char *option) chsrc_use_this_source (pl_php); char *where = " -g "; - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { where = " "; } diff --git a/src/recipe/lang/Python/PDM.c b/src/recipe/lang/Python/PDM.c index a52b582..1ea7844 100644 --- a/src/recipe/lang/Python/PDM.c +++ b/src/recipe/lang/Python/PDM.c @@ -47,7 +47,7 @@ pl_python_pdm_setsrc (char *option) char *cmd = NULL; - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) cmd = xy_2strcat ("pdm config --local pypi.url ", source.url); else cmd = xy_2strcat ("pdm config --global pypi.url ", source.url); diff --git a/src/recipe/lang/Python/Poetry.c b/src/recipe/lang/Python/Poetry.c index 02e9580..c9b2e02 100644 --- a/src/recipe/lang/Python/Poetry.c +++ b/src/recipe/lang/Python/Poetry.c @@ -43,7 +43,7 @@ pl_python_poetry_setsrc (char *option) char *cmd = NULL; - if (!chsrc_in_local_mode()) + if (!chsrc_in_project_scope_mode()) chsrc_alert2 ("Poetry 仅支持项目级换源"); cmd = xy_2strcat ("poetry source add my_mirror ", source.url); diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index 4fdf0ca..7b4061b 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -60,7 +60,7 @@ void pl_python_pip_setsrc (char *option) { // 对于不支持的情况,尽早结束 - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { char *msg = ENGLISH ? "pip doesn't support `-local`. SKIP changing source!" : "pip 不支持 -local,跳过换源"; chsrc_error (msg); diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index 7f2c6fc..eddf08f 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -43,7 +43,7 @@ pl_python_uv_prelude (void) char * pl_python_find_uv_config (bool mkdir) { - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { return xy_2strcat (PL_Python_uv_Local_ConfigPath, PL_Python_uv_ConfigFile); } diff --git a/src/recipe/lang/Ruby/Ruby.c b/src/recipe/lang/Ruby/Ruby.c index a7ab47d..fa8c852 100644 --- a/src/recipe/lang/Ruby/Ruby.c +++ b/src/recipe/lang/Ruby/Ruby.c @@ -88,7 +88,7 @@ pl_ruby_setsrc (char *option) chsrc_ensure_program ("bundle"); char *where = " --global "; - if (chsrc_in_local_mode()) + if (chsrc_in_project_scope_mode()) { where = " --local "; }