From 4b5aff7862df17a04a9c1c29041ca58ea619797b Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Fri, 11 Jul 2025 11:24:29 +0800 Subject: [PATCH] Use new ProgMode --- src/chsrc-main.c | 86 +++++++------- src/framework/core.c | 184 +++++++++++++++--------------- src/recipe/lang/Node.js/Bun.c | 2 +- src/recipe/lang/Node.js/Node.js.c | 4 +- src/recipe/lang/Node.js/Yarn.c | 6 +- src/recipe/lang/Node.js/npm.c | 2 +- src/recipe/lang/Node.js/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/Python.c | 2 +- src/recipe/lang/Python/pip.c | 4 +- src/recipe/lang/Python/uv.c | 2 +- src/recipe/lang/Ruby.c | 2 +- src/recipe/os/APT/Armbian.c | 2 +- src/recipe/os/APT/Debian.c | 2 +- src/recipe/os/APT/Ubuntu.c | 4 +- src/recipe/os/APT/common.h | 4 +- 18 files changed, 158 insertions(+), 156 deletions(-) diff --git a/src/chsrc-main.c b/src/chsrc-main.c index 953fd23..cfa7f88 100644 --- a/src/chsrc-main.c +++ b/src/chsrc-main.c @@ -210,20 +210,20 @@ void cli_print_available_mirrors () { { - char *msg = CliOpt_InEnglish ? "To specify a source, use chsrc set " : "指定使用某源,请使用 chsrc set "; + char *msg = ENGLISH ? "To specify a source, use chsrc set " : "指定使用某源,请使用 chsrc set "; say (bdblue(xy_strjoin (3, msg, "", " \n"))); } { - char *msg = CliOpt_InEnglish ? "Available Mirror Sites: \n" : "可用镜像站: \n"; + char *msg = ENGLISH ? "Available Mirror Sites: \n" : "可用镜像站: \n"; say (bdgreen(msg)); } { - char *msg1 = CliOpt_InEnglish ? "Mirror abbr" : "镜像站简写"; - char *msg2 = CliOpt_InEnglish ? "Mirror URL" : "镜像站URL"; - char *msg3 = CliOpt_InEnglish ? "Mirror Name" : "镜像站"; - char *format = CliOpt_InEnglish ? " %-13s%-28s%-35s%s\n" : " %-13s%-33s%-42s%s\n"; + char *msg1 = ENGLISH ? "Mirror abbr" : "镜像站简写"; + char *msg2 = ENGLISH ? "Mirror URL" : "镜像站URL"; + char *msg3 = ENGLISH ? "Mirror Name" : "镜像站"; + char *format = ENGLISH ? " %-13s%-28s%-35s%s\n" : " %-13s%-33s%-42s%s\n"; printf (format, "code", msg1, msg2, msg3); say ("--------- -------------- ------------------------------------- ---------------------"); } @@ -257,27 +257,27 @@ void cli_print_supported_targets () { { - char *msg = CliOpt_InEnglish ? "Support following targets (same line indicates these targets are compatible)" + char *msg = ENGLISH ? "Support following targets (same line indicates these targets are compatible)" : "支持对以下目标换源 (同一行表示这几个命令兼容)" ; say (bdblue(msg)); br(); } { - char *msg = CliOpt_InEnglish ? "Programming Languages" : "编程语言"; + char *msg = ENGLISH ? "Programming Languages" : "编程语言"; say (bdgreen(msg)); say ("-------------------------"); cli_print_supported_targets_ (pl_packagers, xy_arylen(pl_packagers)); } { - char *msg = CliOpt_InEnglish ? "Operating Systems" : "操作系统"; + char *msg = ENGLISH ? "Operating Systems" : "操作系统"; say (bdgreen(msg)); say ("-------------------------"); cli_print_supported_targets_ (os_systems, xy_arylen(os_systems)); } { - char *msg = CliOpt_InEnglish ? "Softwares" : "软件"; + char *msg = ENGLISH ? "Softwares" : "软件"; say (bdgreen(msg)); say ("-------------------------"); cli_print_supported_targets_ (wr_softwares, xy_arylen(wr_softwares)); @@ -287,7 +287,7 @@ cli_print_supported_targets () void cli_print_supported_pl () { - char *msg = CliOpt_InEnglish ? "Support following Programming Languages (same line indicates these targets are compatible)\n" + char *msg = ENGLISH ? "Support following Programming Languages (same line indicates these targets are compatible)\n" : "支持对以下编程语言生态换源 (同一行表示这几个目标兼容)\n"; say (bdgreen(msg)); @@ -297,7 +297,7 @@ cli_print_supported_pl () void cli_print_supported_os () { - char *msg = CliOpt_InEnglish ? "Support following Operating Systems (same line indicates these targets are compatible)\n" + char *msg = ENGLISH ? "Support following Operating Systems (same line indicates these targets are compatible)\n" : "支持对以下操作系统换源 (同一行表示这几个目标兼容)\n"; say (bdgreen(msg)); cli_print_supported_targets_ (os_systems, xy_arylen(os_systems)); @@ -306,7 +306,7 @@ cli_print_supported_os () void cli_print_supported_wr () { - char *msg = CliOpt_InEnglish ? "Support following Softwares (same line indicates these targets are compatible)\n" + char *msg = ENGLISH ? "Support following Softwares (same line indicates these targets are compatible)\n" : "支持对以下软件换源 (同一行表示这几个目标兼容)\n"; say (bdgreen(msg)); cli_print_supported_targets_ (wr_softwares, xy_arylen(wr_softwares)); @@ -337,19 +337,19 @@ void cli_print_target_features (Feature_t f, const char *input_target_name) { { - char *msg = CliOpt_InEnglish ? "\nAvailable Features:\n" : "\n可用功能:\n"; + char *msg = ENGLISH ? "\nAvailable Features:\n" : "\n可用功能:\n"; say (bdgreen(msg)); } { - char *msg = CliOpt_InEnglish ? " Get: View the current source state " : " Get: 查看当前源状态 "; + char *msg = ENGLISH ? " Get: View the current source state " : " Get: 查看当前源状态 "; char *get_msg = xy_strjoin (3, msg, "| chsrc get ", input_target_name); if (f.can_get) printf (" %s%s\n", bdgreen(YesMark), purple(get_msg)); else printf (" %s%s\n", bdred(NoMark), get_msg);br(); } { - char *msg = CliOpt_InEnglish ? " Reset: Reset to the default source " : " Reset: 重置回默认源 "; + char *msg = ENGLISH ? " Reset: Reset to the default source " : " Reset: 重置回默认源 "; char *reset_msg = xy_strjoin (3, msg, "| chsrc reset ", input_target_name); if (f.can_reset) printf (" %s%s\n", bdgreen(YesMark), purple(reset_msg)); else printf (" %s%s\n", bdred(NoMark), reset_msg);br(); @@ -357,7 +357,7 @@ cli_print_target_features (Feature_t f, const char *input_target_name) { - char *msg = CliOpt_InEnglish ? " UserDefine: using user-defined source URL " : " UserDefine: 用户自定义换源URL "; + char *msg = ENGLISH ? " UserDefine: using user-defined source URL " : " UserDefine: 用户自定义换源URL "; char *user_define_msg = xy_strjoin (5, msg, "| chsrc set ", input_target_name, " https://user-define-url.org/", input_target_name); if (f.can_user_define) printf (" %s%s\n", bdgreen(YesMark), purple(user_define_msg)); else printf (" %s%s\n", bdred(NoMark), user_define_msg);br(); @@ -365,7 +365,7 @@ cli_print_target_features (Feature_t f, const char *input_target_name) { - char *msg = CliOpt_InEnglish ? " Locally: Change source only for this project " : " Locally: 仅对本项目换源 "; + char *msg = ENGLISH ? " Locally: Change source only for this project " : " Locally: 仅对本项目换源 "; char *locally_msg = xy_strjoin (3, msg, "| chsrc set -local ", input_target_name); switch (f.cap_locally) @@ -386,7 +386,7 @@ cli_print_target_features (Feature_t f, const char *input_target_name) { - char *msg = CliOpt_InEnglish ? " English: Output in English " : " English: 英文输出 "; + char *msg = ENGLISH ? " English: Output in English " : " English: 英文输出 "; char *english_msg = xy_strjoin (3, msg, "| chsrc set -en ", input_target_name); if (f.can_english) printf (" %s%s\n", bdgreen(YesMark), purple(english_msg)); else printf (" %s%s\n", bdred(NoMark), english_msg);br(); @@ -394,7 +394,7 @@ cli_print_target_features (Feature_t f, const char *input_target_name) if (f.note) { - char *msg = CliOpt_InEnglish ? "NOTE: " : "备注: "; + char *msg = ENGLISH ? "NOTE: " : "备注: "; printf ("%s%s\n", bdyellow (msg), bdyellow (f.note)); } } @@ -420,7 +420,7 @@ cli_print_help () purple("v" Chsrc_Version "-" Chsrc_Release_Date), " by RubyMetric")); br(); - if (CliOpt_InEnglish) + if (ENGLISH) { for (int i=0; i\n"))); } { - char *msg = CliOpt_InEnglish ? "Available Sources: \n" : "可用源: \n"; + char *msg = ENGLISH ? "Available Sources: \n" : "可用源: \n"; say (bdgreen(msg)); } { - char *msg1 = CliOpt_InEnglish ? "Mirror abbr" : "镜像站简写"; - char *msg2 = CliOpt_InEnglish ? "Source URL" : "换源URL"; - char *msg3 = CliOpt_InEnglish ? "Mirror Name" : "镜像站"; - char *format = CliOpt_InEnglish ? " %-13s%-33s%-38s%s\n" : " %-13s%-36s%-46s%s\n"; + char *msg1 = ENGLISH ? "Mirror abbr" : "镜像站简写"; + char *msg2 = ENGLISH ? "Source URL" : "换源URL"; + char *msg3 = ENGLISH ? "Mirror Name" : "镜像站"; + char *format = ENGLISH ? " %-13s%-33s%-38s%s\n" : " %-13s%-36s%-46s%s\n"; printf (format, "code", msg1, msg2, msg3); say ("--------- -------------- ----------------------------------------------- ---------------------"); } @@ -627,23 +627,23 @@ main (int argc, char const *argv[]) { if (xy_streql (argv[i], "-ipv6")) { - CliOpt_IPv6 = true; + ProgMode.Ipv6Mode = true; } else if (xy_streql (argv[i], "-local")) { - CliOpt_Locally = true; + ProgMode.LocalMode = true; } else if (xy_streql (argv[i], "-en") || xy_streql (argv[i], "-english")) { - CliOpt_InEnglish = true; + ProgMode.EnglishMode = true; } else if (xy_streql (argv[i], "-dry")) { - CliOpt_DryRun = true; + ProgMode.DryRunMode = true; } else if (xy_streql (argv[i], "-no-color") || xy_streql (argv[i], "-no-colour")) { - CliOpt_NoColor = true; + ProgMode.NoColorMode = true; xy_enable_color = false; } else if ( xy_streql (argv[i], "-h") @@ -660,7 +660,7 @@ main (int argc, char const *argv[]) } else { - char *msg = CliOpt_InEnglish ? "Unknown option: " : "未识别的命令行选项 "; + char *msg = ENGLISH ? "Unknown option: " : "未识别的命令行选项 "; chsrc_error (xy_2strjoin (msg, argv[i])); return Exit_Unknown; } cli_arg_Target_pos++; @@ -671,9 +671,9 @@ main (int argc, char const *argv[]) bool matched = false; - if (CliOpt_DryRun) + if (in_dry_run_mode()) { - char *dry_msg = CliOpt_InEnglish ? "Enable [Dry Run] mode. " \ + char *dry_msg = ENGLISH ? "Enable [Dry Run] mode. " \ "Simulate the source changing process (skipping speed measurement). " \ "Commands only print but don't run\n" : "开启Dry Run模式,模拟换源过程(跳过测速),命令仅打印并不运行\n"; @@ -756,12 +756,12 @@ main (int argc, char const *argv[]) { if (argc < cli_arg_Target_pos) { - char *msg = CliOpt_InEnglish ? "Please provide the target name you want to measure. " MSG_EN_USE_LIST_TARGETS + char *msg = ENGLISH ? "Please provide the target name you want to measure. " MSG_EN_USE_LIST_TARGETS : "请您提供想要测速源的目标名。" MSG_CN_USE_LIST_TARGETS; chsrc_error (msg); return Exit_Unknown; } - ProgMode_CMD_Measure = true; + ProgMode.MeasureMode = true; target = argv[cli_arg_Target_pos]; matched = get_target (target, TargetOp_Measure_Source, NULL); if (!matched) goto not_matched; @@ -775,7 +775,7 @@ main (int argc, char const *argv[]) { if (argc < cli_arg_Target_pos) { - char *msg = CliOpt_InEnglish ? "Please provide the target name you want to view the source. " MSG_EN_USE_LIST_TARGETS + char *msg = ENGLISH ? "Please provide the target name you want to view the source. " MSG_EN_USE_LIST_TARGETS : "请您提供想要查看源的目标名。" MSG_CN_USE_LIST_TARGETS; chsrc_error (msg); return Exit_Unknown; @@ -792,7 +792,7 @@ main (int argc, char const *argv[]) { if (argc < cli_arg_Target_pos) { - char *msg = CliOpt_InEnglish ? "Please provide the target name you want to set the source. " MSG_EN_USE_LIST_TARGETS + char *msg = ENGLISH ? "Please provide the target name you want to set the source. " MSG_EN_USE_LIST_TARGETS : "请您提供想要设置源的目标名。" MSG_CN_USE_LIST_TARGETS; chsrc_error (msg); return Exit_Unknown; @@ -817,7 +817,7 @@ main (int argc, char const *argv[]) { if (argc < cli_arg_Target_pos) { - char *msg = CliOpt_InEnglish ? "Please provide the target name you want to reset the source. " MSG_EN_USE_LIST_TARGETS + char *msg = ENGLISH ? "Please provide the target name you want to reset the source. " MSG_EN_USE_LIST_TARGETS : "请您提供想要重置源的目标名。" MSG_CN_USE_LIST_TARGETS; chsrc_error (msg); return Exit_Unknown; @@ -842,8 +842,8 @@ main (int argc, char const *argv[]) else { - char *msg1 = CliOpt_InEnglish ? "Unknown command `" : "不支持的命令 "; - char *msg2 = CliOpt_InEnglish ? "`. Use `chsrc help` to view usage" : ". 请使用 chsrc help 查看使用方式"; + char *msg1 = ENGLISH ? "Unknown command `" : "不支持的命令 "; + char *msg2 = ENGLISH ? "`. Use `chsrc help` to view usage" : ". 请使用 chsrc help 查看使用方式"; chsrc_error (xy_strjoin (3, msg1, command, msg2)); return Exit_Unknown; } @@ -851,7 +851,7 @@ main (int argc, char const *argv[]) not_matched: if (!matched) { - char *msg = CliOpt_InEnglish ? "Unknown target. " MSG_EN_USE_LIST_TARGETS + char *msg = ENGLISH ? "Unknown target. " MSG_EN_USE_LIST_TARGETS : "暂不支持的换源目标。" MSG_CN_USE_LIST_TARGETS; chsrc_error (msg); return Exit_Unknown; diff --git a/src/framework/core.c b/src/framework/core.c index ba4acc6..8f4a9c0 100644 --- a/src/framework/core.c +++ b/src/framework/core.c @@ -82,16 +82,20 @@ ProgMode = .NoColorMode = false }; - +/* recipe 相关 mode */ bool chsrc_in_reset_mode(){return ProgMode.ResetMode;} +bool chsrc_in_local_mode(){return ProgMode.LocalMode;} +bool chsrc_in_english_mode(){return ProgMode.EnglishMode;} +bool chsrc_in_no_color_mode(){return ProgMode.NoColorMode;} -/* 命令行选项 */ -bool CliOpt_IPv6 = false; -bool CliOpt_Locally = false; -bool CliOpt_InEnglish = false; -bool CliOpt_DryRun = false; -bool CliOpt_NoColor = false; +/* Convenience */ +#define ENGLISH chsrc_in_english_mode() +#define CHINESE !chsrc_in_english_mode() +/* 仅 framework 相关 mode */ +static bool in_measure_mode(){return ProgMode.MeasureMode;} +static bool in_ipv6_mode(){return ProgMode.Ipv6Mode;} +static bool in_dry_run_mode(){return ProgMode.DryRunMode;} /** * -local 的含义是启用 *项目级* 换源 @@ -111,8 +115,6 @@ bool CliOpt_NoColor = false; */ -bool ProgMode_CMD_Measure = false; - /* 此时 chsrc_run() 不再是recipe中指定要运行的一个外部命令,而是作为一个功能实现的支撑 */ bool ProgMode_Run_as_a_Service = false; @@ -162,24 +164,24 @@ enum ChgType_t ProgMode_ChgType = ChgType_Auto; #define bdpurple(str) xy_str_to_bold(xy_str_to_purple(str)) // 2系列都是带有括号的 -#define chsrc_succ2(str) xy_succ_brkt(App_Name,CliOpt_InEnglish?"SUCCEED":"成功",str) +#define chsrc_succ2(str) xy_succ_brkt(App_Name,ENGLISH?"SUCCEED":"成功",str) #define chsrc_log2(str) xy_info_brkt(App_Name,"LOG",str) -#define chsrc_warn2(str) xy_warn_brkt(App_Name,CliOpt_InEnglish?"WARN":"警告",str) -#define chsrc_error2(str) xy_error_brkt(App_Name,CliOpt_InEnglish?"ERROR":"错误",str) +#define chsrc_warn2(str) xy_warn_brkt(App_Name,ENGLISH?"WARN":"警告",str) +#define chsrc_error2(str) xy_error_brkt(App_Name,ENGLISH?"ERROR":"错误",str) #define chsrc_debug2(str) xy_warn_brkt(App_Name,"DEBUG",str) #define chsrc_verbose2(str) xy_info_brkt(App_Name,"VERBOSE",str) void chsrc_note2 (const char *str) { - char *msg = CliOpt_InEnglish ? "NOTE" : "提示"; + char *msg = ENGLISH ? "NOTE" : "提示"; xy_log_brkt (yellow(App_Name), bdyellow(msg), yellow(str)); } void chsrc_log_write (const char *filename) { - char *msg = CliOpt_InEnglish ? "WRITE" : "写入"; + char *msg = ENGLISH ? "WRITE" : "写入"; xy_log_brkt (blue(App_Name), bdblue(msg), blue(filename)); } @@ -187,7 +189,7 @@ chsrc_log_write (const char *filename) void chsrc_log_backup (const char *filename) { - char *msg = CliOpt_InEnglish ? "BACKUP" : "备份"; + char *msg = ENGLISH ? "BACKUP" : "备份"; char *bak = xy_2strjoin (filename, ".bak"); xy_log_brkt (blue(App_Name), bdblue(msg), xy_strjoin (3, bdyellow(filename), " -> ", bdgreen(bak))); @@ -205,7 +207,7 @@ log_check_result (const char *check_what, const char *check_type, bool exist) char *not_exist_msg = NULL; char *exist_msg = NULL; - if (CliOpt_InEnglish) + if (ENGLISH) { chk_msg = "CHECK"; not_exist_msg = " doesn't exist"; @@ -239,7 +241,7 @@ log_cmd_result (bool result, int exit_status) char *succ_msg = NULL; char *fail_msg = NULL; - if (CliOpt_InEnglish) + if (ENGLISH) { run_msg = "RUN"; succ_msg = YesMark " executed successfully"; @@ -297,7 +299,7 @@ query_program_exist (char *check_cmd, char *prog_name, int mode) // char buf[32] = {0}; sprintf(buf, "错误码: %d", status); - char *msg = CliOpt_InEnglish ? "command" : "命令"; + char *msg = ENGLISH ? "command" : "命令"; if (0 != status) { @@ -373,8 +375,8 @@ chsrc_ensure_program (char *prog_name) } else { - char *msg1 = CliOpt_InEnglish ? "not found " : "未找到 "; - char *msg2 = CliOpt_InEnglish ? " command, please check for existence" : " 命令,请检查是否存在"; + char *msg1 = ENGLISH ? "not found " : "未找到 "; + char *msg2 = ENGLISH ? " command, please check for existence" : " 命令,请检查是否存在"; chsrc_error (xy_strjoin (3, msg1, prog_name, msg2)); exit (Exit_UserCause); } @@ -384,7 +386,7 @@ chsrc_ensure_program (char *prog_name) bool chsrc_check_file (char *path) { - char *msg = CliOpt_InEnglish ? "file" : "文件"; + char *msg = ENGLISH ? "file" : "文件"; if (xy_file_exist (path)) { log_check_result (path, msg, true); @@ -412,23 +414,23 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input) { if (is_url (input)) { - char *msg = CliOpt_InEnglish ? "Using user-defined sources for this software is not supported at this time, please contact the developers to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持"; + char *msg = ENGLISH ? "Using user-defined sources for this software is not supported at this time, please contact the developers to ask why or request support" : "暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持"; chsrc_error (msg); exit (Exit_Unsupported); } if (0==size) { - char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 "; - char *msg2 = CliOpt_InEnglish ? " doesn't have any source available. Please contact the maintainers" : " 无任何可用源,请联系维护者"; + char *msg1 = ENGLISH ? "Currently " : "当前 "; + char *msg2 = ENGLISH ? " doesn't have any source available. Please contact the maintainers" : " 无任何可用源,请联系维护者"; chsrc_error (xy_strjoin (3, msg1, target, msg2)); exit (Exit_MaintainerCause); } if (1==size) { - char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 "; - char *msg2 = CliOpt_InEnglish ? " only the upstream source exists. Please contact the maintainers" : " 仅存在上游默认源,请联系维护者"; + char *msg1 = ENGLISH ? "Currently " : "当前 "; + char *msg2 = ENGLISH ? " only the upstream source exists. Please contact the maintainers" : " 仅存在上游默认源,请联系维护者"; chsrc_error (xy_strjoin (3, msg1, target, msg2)); exit (Exit_MaintainerCause); } @@ -436,24 +438,24 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input) /* if (xy_streql ("reset", input)) 不再使用这种方式 */ if (chsrc_in_reset_mode()) { - char *msg = CliOpt_InEnglish ? "Will reset to the upstream's default source" : "将重置为上游默认源"; + char *msg = ENGLISH ? "Will reset to the upstream's default source" : "将重置为上游默认源"; say (msg); return 0; /* 返回第1个,因为第1个是上游默认源 */ } if (2==size) { - char *msg1 = CliOpt_InEnglish ? " is " : " 是 "; - char *msg2 = CliOpt_InEnglish ? "'s ONLY mirror available currently, thanks for their generous support" + char *msg1 = ENGLISH ? " is " : " 是 "; + char *msg2 = ENGLISH ? "'s ONLY mirror available currently, thanks for their generous support" : " 目前唯一可用镜像站,感谢他们的慷慨支持"; - const char *name = CliOpt_InEnglish ? sources[1].mirror->abbr + const char *name = ENGLISH ? sources[1].mirror->abbr : sources[1].mirror->name; chsrc_succ (xy_strjoin (4, name, msg1, target, msg2)); } if (xy_streql ("first", input)) { - char *msg = CliOpt_InEnglish ? "Will use the first speedy source measured by maintainers" : "将使用维护团队测速第一的源"; + char *msg = ENGLISH ? "Will use the first speedy source measured by maintainers" : "将使用维护团队测速第一的源"; say (msg); return 1; /* 返回第2个,因为第1个是上游默认源 */ } @@ -475,12 +477,12 @@ query_provider_exist (Source_t *sources, size_t size, char *target, char *input) if (!exist) { { - char *msg1 = CliOpt_InEnglish ? "Mirror site " : "镜像站 "; - char *msg2 = CliOpt_InEnglish ? " doesn't exist" : " 不存在"; + char *msg1 = ENGLISH ? "Mirror site " : "镜像站 "; + char *msg2 = ENGLISH ? " doesn't exist" : " 不存在"; chsrc_error (xy_strjoin (3, msg1, input, msg2)); } - char *msg = CliOpt_InEnglish ? "To see available sources, use chsrc list " : "查看可使用源,请使用 chsrc list "; + char *msg = ENGLISH ? "To see available sources, use chsrc list " : "查看可使用源,请使用 chsrc list "; chsrc_error (xy_2strjoin (msg, target)); exit (Exit_UserCause); } @@ -544,7 +546,7 @@ measure_speed_for_url (void *url) char *ipv6 = ""; // 默认不启用 - if (CliOpt_IPv6==true) + if (in_ipv6_mode()) { ipv6 = "--ipv6"; } @@ -641,8 +643,8 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor if (!skip && NULL==url) // 这种情况应当被视为bug,但是我们目前还是软处理 { - char *msg1 = CliOpt_InEnglish ? "Maintainers don't offer " : "维护者未提供 "; - char *msg2 = CliOpt_InEnglish ? " mirror site's speed measure link, so skip it" : " 镜像站测速链接,跳过该站点"; + char *msg1 = ENGLISH ? "Maintainers don't offer " : "维护者未提供 "; + char *msg2 = ENGLISH ? " mirror site's speed measure link, so skip it" : " 镜像站测速链接,跳过该站点"; chsrc_warn (xy_strjoin (3, msg1, provider->code, msg2)); speed = 0; @@ -676,18 +678,18 @@ measure_speed_for_every_source (Source_t sources[], int size, double speed_recor // get_measured[i] = false; speed_records[i] = speed; - const char *msg = CliOpt_InEnglish ? provider->abbr : provider->name; - const char *skip_reason = CliOpt_InEnglish ? smi.skip_reason_EN : smi.skip_reason_CN; + const char *msg = ENGLISH ? provider->abbr : provider->name; + const char *skip_reason = ENGLISH ? smi.skip_reason_EN : smi.skip_reason_CN; if (NULL==skip_reason) { - skip_reason = CliOpt_InEnglish ? "SKIP for no reason" : "无理由跳过"; + skip_reason = ENGLISH ? "SKIP for no reason" : "无理由跳过"; } measure_msgs[i] = xy_strjoin (4, " x ", msg, " ", yellow(skip_reason)); println (measure_msgs[i]); } else { - const char *msg = CliOpt_InEnglish ? provider->abbr : provider->name; + const char *msg = ENGLISH ? provider->abbr : provider->name; if (xy_streql ("upstream", provider->code)) { @@ -722,22 +724,22 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name) if (chsrc_in_reset_mode()) return 0; - if (!CliOpt_DryRun) + if (!in_dry_run_mode()) { - char *msg = CliOpt_InEnglish ? "Measuring speed in sequence" : "测速中"; - xy_log_brkt (App_Name, bdpurple (CliOpt_InEnglish ? "MEASURE" : "测速"), msg); + char *msg = ENGLISH ? "Measuring speed in sequence" : "测速中"; + xy_log_brkt (App_Name, bdpurple (ENGLISH ? "MEASURE" : "测速"), msg); br(); } if (0==size || 1==size) { - char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 "; - char *msg2 = CliOpt_InEnglish ? "No any source, please contact maintainers: chsrc issue" : " 无任何可用源,请联系维护者: chsrc issue"; + char *msg1 = ENGLISH ? "Currently " : "当前 "; + char *msg2 = ENGLISH ? "No any source, please contact maintainers: chsrc issue" : " 无任何可用源,请联系维护者: chsrc issue"; chsrc_error (xy_strjoin (3, msg1, target_name, msg2)); exit (Exit_MaintainerCause); } - if (CliOpt_DryRun) + if (in_dry_run_mode()) /* Dry Run 时,跳过测速 */ { return 1; /* 原则第一个源 */ @@ -750,7 +752,7 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name) bool exist_curl = chsrc_check_program_quietly_when_exist ("curl"); if (!exist_curl) { - char *msg = CliOpt_InEnglish ? "No curl, unable to measure speed" : "没有curl命令,无法测速"; + char *msg = ENGLISH ? "No curl, unable to measure speed" : "没有curl命令,无法测速"; chsrc_error (msg); exit (Exit_UserCause); } @@ -768,7 +770,7 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name) */ if (strstr (curl_version, "pc-cygwin")) { - char *msg = CliOpt_InEnglish ? "You're using curl built by Cygwin which has a bug! Please use another curl!" : "你使用的是Cygwin构建的curl,该版本的curl存在bug,请改用其他版本的curl"; + char *msg = ENGLISH ? "You're using curl built by Cygwin which has a bug! Please use another curl!" : "你使用的是Cygwin构建的curl,该版本的curl存在bug,请改用其他版本的curl"; chsrc_error (msg); exit (Exit_UserCause); } @@ -792,26 +794,26 @@ select_mirror_autoly (Source_t *sources, size_t size, const char *target_name) if (only_one) { - char *msg1 = CliOpt_InEnglish ? "NOTICE mirror site: " : "镜像站提示: "; - char *is = CliOpt_InEnglish ? " is " : " 是 "; - char *msg2 = CliOpt_InEnglish ? "'s ONLY mirror available currently, thanks for their generous support" + char *msg1 = ENGLISH ? "NOTICE mirror site: " : "镜像站提示: "; + char *is = ENGLISH ? " is " : " 是 "; + char *msg2 = ENGLISH ? "'s ONLY mirror available currently, thanks for their generous support" : " 目前唯一可用镜像站,感谢他们的慷慨支持"; - const char *name = CliOpt_InEnglish ? sources[fast_idx].mirror->abbr + const char *name = ENGLISH ? sources[fast_idx].mirror->abbr : sources[fast_idx].mirror->name; say (xy_strjoin (5, msg1, bdgreen(name), green(is), green(target_name), green(msg2))); } else { - char *msg = CliOpt_InEnglish ? "FASTEST mirror site: " : "最快镜像站: "; - const char *name = CliOpt_InEnglish ? sources[fast_idx].mirror->abbr + char *msg = ENGLISH ? "FASTEST mirror site: " : "最快镜像站: "; + const char *name = ENGLISH ? sources[fast_idx].mirror->abbr : sources[fast_idx].mirror->name; say (xy_2strjoin (msg, green(name))); } // https://github.com/RubyMetric/chsrc/pull/71 - if (ProgMode_CMD_Measure) + if (in_measure_mode()) { - char *msg = CliOpt_InEnglish ? "URL of above source: " : "镜像源地址: "; + char *msg = ENGLISH ? "URL of above source: " : "镜像源地址: "; say (xy_2strjoin (msg, green(sources[fast_idx].url))); } @@ -905,20 +907,20 @@ confirm_source (Source_t *source) // 之所以禁用,是因为有的 reset 我们并没有实现,我们在这里阻止这些邪恶的用户 if (source_is_upstream (source) && source_has_empty_url (source)) { - char *msg = CliOpt_InEnglish ? "Not implement `reset` for the target yet" : "暂未对该目标实现重置"; + char *msg = ENGLISH ? "Not implement `reset` for the target yet" : "暂未对该目标实现重置"; chsrc_error (msg); exit (Exit_Unsupported); } else if (source_has_empty_url (source)) { - char *msg = CliOpt_InEnglish ? "URL of the source doesn't exist, please report a bug to the dev team" : \ + char *msg = ENGLISH ? "URL of the source doesn't exist, please report a bug to the dev team" : \ "该源URL不存在,请向维护团队提交bug"; chsrc_error (msg); exit (Exit_MaintainerCause); } else { - char *msg = CliOpt_InEnglish ? "SELECT mirror site: " : "选中镜像站: "; + char *msg = ENGLISH ? "SELECT mirror site: " : "选中镜像站: "; say (xy_strjoin (5, msg, green (source->mirror->abbr), " (", green (source->mirror->code), ")")); } @@ -957,7 +959,7 @@ chsrc_determine_chgtype (enum ChgType_t type) #define MSG_EN_STILL "Still need to operate manually according to the above prompts. " #define MSG_CN_STILL "仍需按上述提示手工操作" -#define thank_mirror(msg) chsrc_log(xy_2strjoin(msg,purple(CliOpt_InEnglish?source->mirror->abbr:source->mirror->name))) +#define thank_mirror(msg) chsrc_log(xy_2strjoin(msg,purple(ENGLISH?source->mirror->abbr:source->mirror->name))) /** * @param source 可为NULL @@ -973,7 +975,7 @@ chsrc_conclude (Source_t *source) if (chsrc_in_reset_mode()) { // source_is_upstream (source) - char *msg = CliOpt_InEnglish ? "Has been reset to the upstream default source" : "已重置为上游默认源"; + char *msg = ENGLISH ? "Has been reset to the upstream default source" : "已重置为上游默认源"; chsrc_log (purple (msg)); } else if (ChgType_Auto == ProgMode_ChgType) @@ -982,20 +984,20 @@ chsrc_conclude (Source_t *source) { if (source_is_userdefine (source)) { - char *msg = CliOpt_InEnglish ? MSG_EN_FULLY_AUTO MSG_EN_PUBLIC_URL \ + char *msg = ENGLISH ? MSG_EN_FULLY_AUTO MSG_EN_PUBLIC_URL \ : MSG_CN_FULLY_AUTO ", " MSG_CN_PUBLIC_URL; chsrc_log (msg); } else { - char *msg = CliOpt_InEnglish ? MSG_EN_FULLY_AUTO MSG_EN_THANKS \ + char *msg = ENGLISH ? MSG_EN_FULLY_AUTO MSG_EN_THANKS \ : MSG_CN_FULLY_AUTO ", " MSG_CN_THANKS; thank_mirror (msg); } } else { - char *msg = CliOpt_InEnglish ? MSG_EN_FULLY_AUTO : MSG_CN_FULLY_AUTO; + char *msg = ENGLISH ? MSG_EN_FULLY_AUTO : MSG_CN_FULLY_AUTO; chsrc_log (msg); } } @@ -1005,25 +1007,25 @@ chsrc_conclude (Source_t *source) { if (source_is_userdefine (source)) { - char *msg = CliOpt_InEnglish ? MSG_EN_SEMI_AUTO MSG_EN_STILL MSG_EN_PUBLIC_URL \ + char *msg = ENGLISH ? MSG_EN_SEMI_AUTO MSG_EN_STILL MSG_EN_PUBLIC_URL \ : MSG_CN_SEMI_AUTO ", " MSG_CN_STILL "。" MSG_CN_PUBLIC_URL; chsrc_log (msg); } else { - char *msg = CliOpt_InEnglish ? MSG_EN_SEMI_AUTO MSG_EN_STILL MSG_EN_THANKS \ + char *msg = ENGLISH ? MSG_EN_SEMI_AUTO MSG_EN_STILL MSG_EN_THANKS \ : MSG_CN_SEMI_AUTO ", " MSG_CN_STILL "。" MSG_CN_THANKS; thank_mirror (msg); } } else { - char *msg = CliOpt_InEnglish ? MSG_EN_SEMI_AUTO MSG_EN_STILL \ + char *msg = ENGLISH ? MSG_EN_SEMI_AUTO MSG_EN_STILL \ : MSG_CN_SEMI_AUTO ", " MSG_CN_STILL; chsrc_log (msg); } - char *msg = CliOpt_InEnglish ? MSG_EN_BETTER : MSG_CN_BETTER; + char *msg = ENGLISH ? MSG_EN_BETTER : MSG_CN_BETTER; chsrc_warn (msg); } else if (ChgType_Manual == ProgMode_ChgType) @@ -1032,23 +1034,23 @@ chsrc_conclude (Source_t *source) { if (source_is_userdefine (source)) { - char *msg = CliOpt_InEnglish ? MSG_EN_CONSTRAINT MSG_EN_PUBLIC_URL \ + char *msg = ENGLISH ? MSG_EN_CONSTRAINT MSG_EN_PUBLIC_URL \ : MSG_CN_CONSTRAINT "; " MSG_CN_PUBLIC_URL; chsrc_log (msg); } else { - char *msg = CliOpt_InEnglish ? MSG_EN_CONSTRAINT MSG_EN_THANKS \ + char *msg = ENGLISH ? MSG_EN_CONSTRAINT MSG_EN_THANKS \ : MSG_CN_CONSTRAINT ", " MSG_CN_THANKS; thank_mirror (msg); } } else { - char *msg = CliOpt_InEnglish ? MSG_EN_CONSTRAINT : MSG_CN_CONSTRAINT; + char *msg = ENGLISH ? MSG_EN_CONSTRAINT : MSG_CN_CONSTRAINT; chsrc_log (msg); } - char *msg = CliOpt_InEnglish ? MSG_EN_BETTER : MSG_CN_BETTER; + char *msg = ENGLISH ? MSG_EN_BETTER : MSG_CN_BETTER; chsrc_warn (msg); } else if (ChgType_Untested == ProgMode_ChgType) @@ -1057,22 +1059,22 @@ chsrc_conclude (Source_t *source) { if (source_is_userdefine (source)) { - char *msg = CliOpt_InEnglish ? MSG_EN_PUBLIC_URL : MSG_CN_PUBLIC_URL; + char *msg = ENGLISH ? MSG_EN_PUBLIC_URL : MSG_CN_PUBLIC_URL; chsrc_log (msg); } else { - char *msg = CliOpt_InEnglish ? MSG_EN_THANKS : MSG_CN_THANKS; + char *msg = ENGLISH ? MSG_EN_THANKS : MSG_CN_THANKS; thank_mirror (msg); } } else { - char *msg = CliOpt_InEnglish ? "Auto changed source" : "自动换源完成"; + char *msg = ENGLISH ? "Auto changed source" : "自动换源完成"; chsrc_log (msg); } - char *msg = CliOpt_InEnglish ? "The method hasn't been tested or has any feedback, please report usage: chsrc issue" : "该换源步骤已实现但未经测试或存在任何反馈,请报告使用情况: chsrc issue"; + char *msg = ENGLISH ? "The method hasn't been tested or has any feedback, please report usage: chsrc issue" : "该换源步骤已实现但未经测试或存在任何反馈,请报告使用情况: chsrc issue"; chsrc_warn (msg); } else @@ -1102,7 +1104,7 @@ chsrc_ensure_root () char *msg = NULL; not_root: - msg = CliOpt_InEnglish ? "Use sudo before the command or switch to root to ensure the necessary permissions" + msg = ENGLISH ? "Use sudo before the command or switch to root to ensure the necessary permissions" : "请在命令前使用 sudo 或切换为root用户来保证必要的权限"; chsrc_error (msg); exit (Exit_UserCause); @@ -1123,13 +1125,13 @@ chsrc_run (const char *cmd, int run_option) } else { - if (CliOpt_InEnglish) + if (ENGLISH) xy_log_brkt (blue (App_Name), bdblue ("RUN"), blue (cmd)); else xy_log_brkt (blue (App_Name), bdblue ("运行"), blue (cmd)); } - if (CliOpt_DryRun) + if (in_dry_run_mode()) { return; // Dry Run 此时立即结束,并不真正执行 } @@ -1147,7 +1149,7 @@ chsrc_run (const char *cmd, int run_option) log_cmd_result (false, status); if (! (run_option & RunOpt_Dont_Abort_On_Failure)) { - char *msg = CliOpt_InEnglish ? "Fatal error, forced end" : "关键错误,强制结束"; + char *msg = ENGLISH ? "Fatal error, forced end" : "关键错误,强制结束"; chsrc_error (msg); exit (Exit_ExternalError); } @@ -1268,7 +1270,7 @@ chsrc_ensure_dir (const char *dir) chsrc_run_as_a_service (cmd); - char *msg = CliOpt_InEnglish ? "Directory doesn't exist, created automatically " : "目录不存在,已自动创建 "; + char *msg = ENGLISH ? "Directory doesn't exist, created automatically " : "目录不存在,已自动创建 "; chsrc_note2 (xy_2strjoin (msg, dir)); } @@ -1276,7 +1278,7 @@ chsrc_ensure_dir (const char *dir) static void chsrc_append_to_file (const char *str, const char *filename) { - if (CliOpt_DryRun) + if (in_dry_run_mode()) { goto log_anyway; } @@ -1288,7 +1290,7 @@ chsrc_append_to_file (const char *str, const char *filename) FILE *f = fopen (file, "a"); if (NULL==f) { - char *msg = CliOpt_InEnglish ? xy_2strjoin ("Unable to open file to write: ", file) + char *msg = ENGLISH ? xy_2strjoin ("Unable to open file to write: ", file) : xy_2strjoin ("无法打开文件以写入: ", file); chsrc_error2 (msg); exit (Exit_UserCause); @@ -1299,7 +1301,7 @@ chsrc_append_to_file (const char *str, const char *filename) size_t ret = fwrite (str, len, 1, f); if (ret != 1) { - char *msg = CliOpt_InEnglish ? xy_2strjoin ("Write failed to ", file) + char *msg = ENGLISH ? xy_2strjoin ("Write failed to ", file) : xy_2strjoin ("写入文件失败: ", file); chsrc_error2 (msg); exit (Exit_UserCause); @@ -1328,7 +1330,7 @@ log_anyway: static void chsrc_prepend_to_file (const char *str, const char *filename) { - if (CliOpt_DryRun) + if (in_dry_run_mode()) { goto log_anyway; } @@ -1356,7 +1358,7 @@ log_anyway: static void chsrc_overwrite_file (const char *str, const char *filename) { - if (CliOpt_DryRun) + if (in_dry_run_mode()) { goto log_anyway; } @@ -1384,7 +1386,7 @@ log_anyway: static void chsrc_backup (const char *path) { - if (CliOpt_DryRun) + if (in_dry_run_mode()) { goto log_anyway; } @@ -1394,7 +1396,7 @@ chsrc_backup (const char *path) if (!exist) { - char *msg = CliOpt_InEnglish ? "File doesn't exist, skip backup: " : "文件不存在,跳过备份: "; + char *msg = ENGLISH ? "File doesn't exist, skip backup: " : "文件不存在,跳过备份: "; chsrc_note2 (xy_2strjoin (msg, path)); return; } @@ -1466,7 +1468,7 @@ chsrc_get_cpuarch () ret = "IA-64"; break; case PROCESSOR_ARCHITECTURE_UNKNOWN: default: - msg = CliOpt_InEnglish ? "Unable to detect CPU type" : "无法检测到CPU类型"; + msg = ENGLISH ? "Unable to detect CPU type" : "无法检测到CPU类型"; chsrc_error (msg); exit (Exit_UserCause); } @@ -1490,7 +1492,7 @@ chsrc_get_cpuarch () } else { - msg = CliOpt_InEnglish ? "Unable to detect CPU type" : "无法检测到CPU类型"; + msg = ENGLISH ? "Unable to detect CPU type" : "无法检测到CPU类型"; chsrc_error (msg); exit (Exit_UserCause); } diff --git a/src/recipe/lang/Node.js/Bun.c b/src/recipe/lang/Node.js/Bun.c index 456645c..9c7288e 100644 --- a/src/recipe/lang/Node.js/Bun.c +++ b/src/recipe/lang/Node.js/Bun.c @@ -33,7 +33,7 @@ pl_nodejs_bun_setsrc (char *option) char *file = xy_strjoin(3, "[install]\n" "registry = \"", source.url, "\""); - if (CliOpt_Locally==true) + if (chsrc_in_local_mode()) { chsrc_note2 ("请您手动写入以下内容到本项目根目录的 bunfig.toml 文件中"); } diff --git a/src/recipe/lang/Node.js/Node.js.c b/src/recipe/lang/Node.js/Node.js.c index 1474f26..e103ba0 100644 --- a/src/recipe/lang/Node.js/Node.js.c +++ b/src/recipe/lang/Node.js/Node.js.c @@ -18,7 +18,7 @@ pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist) if (!*npm_exist && !*yarn_exist && !*pnpm_exist) { - char *msg = CliOpt_InEnglish ? "No npm, yarn or pnpm command found, check if at least one is present" + char *msg = ENGLISH ? "No npm, yarn or pnpm command found, check if at least one is present" : "未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"; chsrc_error (msg); exit (Exit_UserCause); @@ -64,7 +64,7 @@ void pl_nodejs_setsrc (char *option) { { - char *msg = CliOpt_InEnglish ? "Three package managers will be replaced for you at the same time: " \ + char *msg = ENGLISH ? "Three package managers will be replaced for you at the same time: " \ "npm, pnpm, yarn. If you need to change the source independently, " \ "please run independently `chsrc set `" : "将同时为您更换3个包管理器 npm, pnpm, Yarn 的源,若需要独立换源,请独立运行 chsrc set "; diff --git a/src/recipe/lang/Node.js/Yarn.c b/src/recipe/lang/Node.js/Yarn.c index a162987..b0c5dcb 100644 --- a/src/recipe/lang/Node.js/Yarn.c +++ b/src/recipe/lang/Node.js/Yarn.c @@ -50,7 +50,7 @@ pl_nodejs_yarn_setsrc (char *option) // 从 Yarn V2 开始,使用新的配置名 if (pl_nodejs_yarn_get_yarn_version () >= 2) { - if (CliOpt_Locally==true) // Yarn 默认情况下就是基于本项目换源 + if (chsrc_in_local_mode()) // Yarn 默认情况下就是基于本项目换源 cmd = xy_2strjoin ("yarn config set npmRegistryServer ", source.url); else cmd = xy_2strjoin ("yarn config set npmRegistryServer --home ", source.url); @@ -59,9 +59,9 @@ pl_nodejs_yarn_setsrc (char *option) } else { - if (CliOpt_Locally) + if (chsrc_in_local_mode()) { - char *msg = CliOpt_InEnglish ? "Yarn v1 doesn't support `-local`. SKIP changing source!" : "Yarn v1 不支持 -local,跳过换源"; + char *msg = ENGLISH ? "Yarn v1 doesn't support `-local`. SKIP changing source!" : "Yarn v1 不支持 -local,跳过换源"; chsrc_error (msg); // 不能直接退出,因为 Leader target 不能就此结束 return; diff --git a/src/recipe/lang/Node.js/npm.c b/src/recipe/lang/Node.js/npm.c index eba4314..6f28fa7 100644 --- a/src/recipe/lang/Node.js/npm.c +++ b/src/recipe/lang/Node.js/npm.c @@ -33,7 +33,7 @@ pl_nodejs_npm_setsrc (char *option) char *cmd = NULL; - if (CliOpt_Locally==true) + if (chsrc_in_local_mode()) cmd = xy_2strjoin ("npm config --location project set registry ", source.url); else cmd = xy_2strjoin ("npm config set registry ", source.url); diff --git a/src/recipe/lang/Node.js/pnpm.c b/src/recipe/lang/Node.js/pnpm.c index a241f04..9d6315b 100644 --- a/src/recipe/lang/Node.js/pnpm.c +++ b/src/recipe/lang/Node.js/pnpm.c @@ -34,7 +34,7 @@ pl_nodejs_pnpm_setsrc (char *option) char *cmd = NULL; - if (CliOpt_Locally) + if (chsrc_in_local_mode()) cmd = xy_2strjoin ("pnpm config --location project set registry ", source.url); else cmd = xy_2strjoin ("pnpm config -g set registry ", source.url); diff --git a/src/recipe/lang/PHP.c b/src/recipe/lang/PHP.c index 5b442b4..f9fe4a2 100644 --- a/src/recipe/lang/PHP.c +++ b/src/recipe/lang/PHP.c @@ -49,7 +49,7 @@ pl_php_setsrc (char *option) chsrc_yield_source_and_confirm (pl_php); char *where = " -g "; - if (CliOpt_Locally==true) + if (chsrc_in_local_mode()) { where = " "; } diff --git a/src/recipe/lang/Python/PDM.c b/src/recipe/lang/Python/PDM.c index 32deb2e..326f7c3 100644 --- a/src/recipe/lang/Python/PDM.c +++ b/src/recipe/lang/Python/PDM.c @@ -35,7 +35,7 @@ pl_python_pdm_setsrc (char *option) char *cmd = NULL; - if (CliOpt_Locally==true) + if (chsrc_in_local_mode()) cmd = xy_2strjoin ("pdm config --local pypi.url ", source.url); else cmd = xy_2strjoin ("pdm config --global pypi.url ", source.url); diff --git a/src/recipe/lang/Python/Poetry.c b/src/recipe/lang/Python/Poetry.c index c68d837..fe9cacb 100644 --- a/src/recipe/lang/Python/Poetry.c +++ b/src/recipe/lang/Python/Poetry.c @@ -34,7 +34,7 @@ pl_python_poetry_setsrc (char *option) char *cmd = NULL; - if (CliOpt_Locally==false) + if (!chsrc_in_local_mode()) chsrc_note2 ("Poertry 仅支持项目级换源"); cmd = xy_2strjoin ("poetry source add my_mirror ", source.url); diff --git a/src/recipe/lang/Python/Python.c b/src/recipe/lang/Python/Python.c index b17608c..efc0201 100644 --- a/src/recipe/lang/Python/Python.c +++ b/src/recipe/lang/Python/Python.c @@ -44,7 +44,7 @@ void pl_python_setsrc (char *option) { { - char *msg = CliOpt_InEnglish ? "Three package managers will be replaced for you at the same time: " \ + char *msg = ENGLISH ? "Three package managers will be replaced for you at the same time: " \ "pip, Poetry, PDM. If you need to change the source independently, " \ "please run independently `chsrc set `" : "将同时为您更换4个包管理器 pip, Poetry, PDM, uv 的源,若需要独立换源,请独立运行 chsrc set "; diff --git a/src/recipe/lang/Python/pip.c b/src/recipe/lang/Python/pip.c index 089b424..052c585 100644 --- a/src/recipe/lang/Python/pip.c +++ b/src/recipe/lang/Python/pip.c @@ -30,9 +30,9 @@ void pl_python_pip_setsrc (char *option) { // 对于不支持的情况,尽早结束 - if (CliOpt_Locally) + if (chsrc_in_local_mode()) { - char *msg = CliOpt_InEnglish ? "pip doesn't support `-local`. SKIP changing source!" : "pip 不支持 -local,跳过换源"; + char *msg = ENGLISH ? "pip doesn't support `-local`. SKIP changing source!" : "pip 不支持 -local,跳过换源"; chsrc_error (msg); // 不能直接退出,因为 Leader target 不能就此结束 return; diff --git a/src/recipe/lang/Python/uv.c b/src/recipe/lang/Python/uv.c index 519456d..383afdc 100644 --- a/src/recipe/lang/Python/uv.c +++ b/src/recipe/lang/Python/uv.c @@ -27,7 +27,7 @@ char * pl_python_find_uv_config (bool mkdir) { - if (CliOpt_Locally) + if (chsrc_in_local_mode()) { return xy_2strjoin (UV_LOCAL_CONFIG_PATH, UV_CONFIG); } diff --git a/src/recipe/lang/Ruby.c b/src/recipe/lang/Ruby.c index e1ec0fe..cba3f2c 100644 --- a/src/recipe/lang/Ruby.c +++ b/src/recipe/lang/Ruby.c @@ -83,7 +83,7 @@ pl_ruby_setsrc (char *option) chsrc_ensure_program ("bundle"); char *where = " --global "; - if (CliOpt_Locally==true) + if (chsrc_in_local_mode()) { where = " --local "; } diff --git a/src/recipe/os/APT/Armbian.c b/src/recipe/os/APT/Armbian.c index 07fcb0f..ac98197 100644 --- a/src/recipe/os/APT/Armbian.c +++ b/src/recipe/os/APT/Armbian.c @@ -35,7 +35,7 @@ os_armbian_getsrc (char *option) return; } - char *msg = CliOpt_InEnglish ? "Source list config file missing! Path: " OS_Armbian_SourceList + char *msg = ENGLISH ? "Source list config file missing! Path: " OS_Armbian_SourceList : "缺少源配置文件!路径:" OS_Armbian_SourceList; chsrc_error2 (msg); } diff --git a/src/recipe/os/APT/Debian.c b/src/recipe/os/APT/Debian.c index 62e3f4d..9ee1d23 100644 --- a/src/recipe/os/APT/Debian.c +++ b/src/recipe/os/APT/Debian.c @@ -53,7 +53,7 @@ os_debian_getsrc (char *option) return; } - char *msg = CliOpt_InEnglish ? "Source list file missing! However, you can still run `chsrc set debian` to add and use new sources" + char *msg = ENGLISH ? "Source list file missing! However, you can still run `chsrc set debian` to add and use new sources" : "缺少源配置文件!但仍可直接通过 chsrc set debian 来添加使用新的源"; chsrc_error2 (msg); return; diff --git a/src/recipe/os/APT/Ubuntu.c b/src/recipe/os/APT/Ubuntu.c index 310afc0..cc908ba 100644 --- a/src/recipe/os/APT/Ubuntu.c +++ b/src/recipe/os/APT/Ubuntu.c @@ -52,7 +52,7 @@ os_ubuntu_getsrc (char *option) return; } - char *msg = CliOpt_InEnglish ? "Source list file missing! However, you can still run `chsrc set ubuntu` to add and use new sources" + char *msg = ENGLISH ? "Source list file missing! However, you can still run `chsrc set ubuntu` to add and use new sources" : "缺少源配置文件!但仍可直接通过 chsrc set ubuntu 来添加使用新的源"; chsrc_error2 (msg); return; @@ -97,7 +97,7 @@ os_ubuntu_setsrc (char *option) if (chsrc_check_file (OS_Ubuntu_SourceList_DEB822)) { - char *msg = CliOpt_InEnglish ? "Will change source based on new format" + char *msg = ENGLISH ? "Will change source based on new format" : "将基于新格式(DEB822)换源"; chsrc_note2 (msg); os_ubuntu_setsrc_for_deb822 (option); diff --git a/src/recipe/os/APT/common.h b/src/recipe/os/APT/common.h index 4a3d4d3..4f33820 100644 --- a/src/recipe/os/APT/common.h +++ b/src/recipe/os/APT/common.h @@ -62,7 +62,7 @@ ensure_debian_or_ubuntu_old_sourcelist (int debian_type) } else { - char *msg = CliOpt_InEnglish ? "Will generate a new source list file" + char *msg = ENGLISH ? "Will generate a new source list file" : "将生成新的源配置文件"; chsrc_note2 (msg); } @@ -123,7 +123,7 @@ ensure_debian_or_ubuntu_old_sourcelist (int debian_type) } else { - char *msg = CliOpt_InEnglish ? "Your Debian version is too low (<10) for chsrc to support" + char *msg = ENGLISH ? "Your Debian version is too low (<10) for chsrc to support" : "您的 Debian 版本过低 (<10),暂不支持换源"; chsrc_error (msg); exit (Exit_Unsupported);