Use chsrc_determine_chgtype()

This commit is contained in:
Aoran Zeng
2025-03-06 12:36:16 +08:00
parent 7226eecf3d
commit 2d75a48c19
67 changed files with 113 additions and 85 deletions

View File

@@ -27,7 +27,8 @@ pl_clojure_setsrc (char *option)
chsrc_note2 ("抱歉Clojure换源较复杂您可手动查阅并换源:");
p(source.url);
ProgMode_ChgType = ChgType_Manual;
chsrc_determine_chgtype (ChgType_Manual);
chsrc_conclude (&source);
}

View File

@@ -84,7 +84,7 @@ pl_dart_flutter_setsrc (char *option)
}
}
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -80,7 +80,7 @@ pl_dart_setsrc (char *option)
}
}
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -83,7 +83,8 @@ pl_go_setsrc (char *option)
cmd = xy_strjoin (3, "go env -w GOPROXY=", source.url, ",direct");
chsrc_run (cmd, RunOpt_Default);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -62,7 +62,8 @@ pl_haskell_setsrc (char *option)
chsrc_note2 (xy_strjoin (3, "请向 ", config, " 中手动添加:"));
p(file);
ProgMode_ChgType = ChgType_Manual;
chsrc_determine_chgtype (ChgType_Manual);
chsrc_conclude (&source);
}

View File

@@ -101,7 +101,8 @@ pl_java_setsrc (char *option)
chsrc_note2 ("请在您的 build.gradle 中添加:");
p(file);
}
ProgMode_ChgType = ChgType_Manual;
chsrc_determine_chgtype (ChgType_Manual);
chsrc_conclude (&source);
}

View File

@@ -49,7 +49,7 @@ pl_julia_setsrc (char *option)
chsrc_append_to_file (w, PL_Julia_Config);
ProgMode_ChgType = ChgType_Untested;
chsrc_determine_chgtype (ChgType_Untested);
chsrc_conclude (&source);
}

View File

@@ -34,7 +34,7 @@ pl_lua_getsrc (char *option)
}
/**
* Lua 换源,参考:https://luarocks.cn/
* @consult https://luarocks.cn/
*/
void
pl_lua_setsrc (char *option)
@@ -54,7 +54,7 @@ pl_lua_setsrc (char *option)
chsrc_note2 ("请手动修改 ~/.luarocks/upload_config.lua 文件 (用于上传):");
p(upload_config);
ProgMode_ChgType = ChgType_Manual;
chsrc_determine_chgtype (ChgType_Manual);
chsrc_conclude (&source);
}

View File

@@ -43,7 +43,8 @@ pl_nodejs_bun_setsrc (char *option)
}
p(file);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -94,7 +94,7 @@ pl_nodejs_setsrc (char *option)
pl_nodejs_pnpm_setsrc (option);
}
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -73,7 +73,7 @@ pl_nodejs_yarn_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -42,7 +42,7 @@ pl_nodejs_npm_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -42,7 +42,7 @@ pl_nodejs_nvm_setsrc (char *option)
if (xy_file_exist (zshrc))
chsrc_append_to_file (w, zshrc);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -43,7 +43,7 @@ pl_nodejs_pnpm_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -24,18 +24,20 @@ pl_ocaml_check_cmd ()
chsrc_ensure_program ("opam");
}
void
pl_ocaml_getsrc(char *option)
pl_ocaml_getsrc (char *option)
{
pl_ocaml_check_cmd ();
chsrc_run ("opam repo get-url default", RunOpt_Default);
}
/**
* 参考: https://mirrors.sjtug.sjtu.edu.cn/docs/git/opam-repository.git
* @consult https://mirrors.sjtug.sjtu.edu.cn/docs/git/opam-repository.git
*/
void
pl_ocaml_setsrc(char *option)
pl_ocaml_setsrc (char *option)
{
pl_ocaml_check_cmd ();
@@ -50,7 +52,7 @@ pl_ocaml_setsrc(char *option)
chsrc_note2 ("如果是首次使用 opam ,请使用以下命令进行初始化");
p(xy_2strjoin ("opam init default ", source.url));
ProgMode_ChgType = ChgType_SemiAuto;
chsrc_determine_chgtype (ChgType_SemiAuto);
chsrc_conclude (&source);
}

View File

@@ -57,7 +57,7 @@ pl_php_setsrc (char *option)
char *cmd = xy_strjoin (4, "composer config", where, "repo.packagist composer ", source.url);
chsrc_run (cmd, RunOpt_Default);
ProgMode_ChgType = ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -63,7 +63,7 @@ pl_perl_setsrc (char *option)
chsrc_note2 ("请您使用 perl -v 以及 cpan -v若 Perl >= v5.36 或 CPAN >= 2.29,请额外手动调用下面的命令");
p("perl -MCPAN -e \"CPAN::HandleConfig->load(); CPAN::HandleConfig->edit('pushy_https', 0);; CPAN::HandleConfig->commit()\"");
ProgMode_ChgType = ChgType_SemiAuto;
chsrc_determine_chgtype (ChgType_SemiAuto);
chsrc_conclude (&source);
}

View File

@@ -44,7 +44,7 @@ pl_python_pdm_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -42,7 +42,7 @@ pl_python_poetry_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -81,7 +81,7 @@ pl_python_setsrc (char *option)
pl_python_uv_setsrc (option);
}
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -49,7 +49,7 @@ pl_python_rye_setsrc (char *option)
chsrc_note2 (xy_strjoin (3, "请在您的 Rye 配置文件 ", rye_config, " 中添加:"));
puts (file);
ProgMode_ChgType = ChgType_Manual;
chsrc_determine_chgtype (ChgType_Manual);
chsrc_conclude (&source);
}

View File

@@ -54,7 +54,7 @@ pl_python_pip_setsrc (char *option)
if (ProgMode_Target_Group!=true)
{
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}
}

View File

@@ -67,28 +67,28 @@ void
pl_python_uv_setsrc (char *option)
{
chsrc_ensure_program("uv");
Source_t source;
chsrc_yield_for_the_source (pl_python);
char *uv_config = pl_python_find_uv_config (true);
chsrc_backup (uv_config);
const char *source_content = xy_strjoin (5,
"[[index]]\n",
"url = \"", source.url, "\"\n",
"default = true\n");
// sed -i '/^\[\[index\]\]$/,/^default = true$/{s|^url = ".*"$|url = " source.url "|}' uv_config
// 将 [[index]] 到 default = true 之间的 url = ".*" 替换为 url = "source.url"
char *update_source_cmd = xy_strjoin (5, "sed -i ",
"'/^\\[\\[index\\]\\]$/,/^default = true$/{s|^url = \".*\"$|url = \"",
source.url,
source.url,
"\"|}' ",
uv_config);
char *append_source_cmd = xy_strjoin (4, "echo -e '", source_content, "' >> ", uv_config);
// grep -q '^[[index]]$' uv_config && update_source_cmd || append_source_cmd
// 如果 uv_config 中存在 [[index]] 则更新, 否则追加到文件末尾
// 文件不存在也是追加到新文件末尾
@@ -98,8 +98,11 @@ pl_python_uv_setsrc (char *option)
update_source_cmd,
" || ",
append_source_cmd);
chsrc_run (cmd, RunOpt_Default);
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -71,7 +71,7 @@ pl_r_setsrc (char *option)
chsrc_append_to_file (w, config);
ProgMode_ChgType = ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -91,7 +91,7 @@ pl_ruby_setsrc (char *option)
cmd = xy_strjoin (4, "bundle config", where, "'mirror.https://rubygems.org' ", source.url);
chsrc_run (cmd, RunOpt_No_Last_New_Line);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -63,7 +63,8 @@ pl_rust_cargo_setsrc (char *option)
chsrc_note2 (xy_strjoin (3, "请您手动写入以下内容到 ", xy_normalize_path ("~/.cargo/config.toml"), " 文件中:"));
p(file);
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
}

View File

@@ -84,7 +84,7 @@ pl_rust_rustup_setsrc (char *option)
chsrc_append_to_file (w, fishrc);
}
ProgMode_ChgType = ProgMode_CMD_Reset ? ChgType_Reset : ChgType_Auto;
chsrc_determine_chgtype (ChgType_Auto);
chsrc_conclude (&source);
chsrc_note2 ("请您重启终端使rustup环境变量生效");
}