mirror of
https://github.com/RubyMetric/chsrc
synced 2025-10-21 02:11:28 +08:00
Use chsrc_determine_chgtype()
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user