Add English help

This commit is contained in:
Aoran Zeng 2024-08-22 22:26:26 +08:00
parent 0a69ff40c0
commit ade48440c8
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -100,11 +100,10 @@
static const char * static const char *
Chsrc_Usage[] = { Chsrc_Usage[] = {
"维护: " Chsrc_Maintain_URL "\n",
"使用: chsrc <command> [options] [target] [mirror]", "使用: chsrc <command> [options] [target] [mirror]",
"help 打印此帮助,或 h, -h, --help", "help 打印此帮助,或 h, -h, --help",
"issue 查看相关issue\n", "issue 查看相关issue\n",
"list (或 ls, 或 l) 列出可用镜像源,和可换源目标", "list (或 ls, 或 l) 列出可用镜像源,和可换源目标",
"list mirror/target 列出可用镜像源,或可换源目标", "list mirror/target 列出可用镜像源,或可换源目标",
"list os/lang/ware 列出可换源的操作系统/编程语言/软件\n", "list os/lang/ware 列出可换源的操作系统/编程语言/软件\n",
@ -124,7 +123,41 @@ Chsrc_Usage[] = {
"选项:", "选项:",
"-dry Dry Run模拟换源过程命令仅打印并不运行", "-dry Dry Run模拟换源过程命令仅打印并不运行",
"-ipv6 使用IPv6测速", "-ipv6 使用IPv6测速",
"-local 仅对本项目而非全局换源 (通过ls <target>查看支持情况)" "-local 仅对本项目而非全局换源 (通过ls <target>查看支持情况)",
"-en(glish) 使用英文输出\n",
"维护: <" Chsrc_Maintain_URL ">"
};
static const char *
Chsrc_Usage_English[] = {
"Usage: chsrc <command> [options] [target] [mirror]",
"help Print this help, or h, -h, --help",
"issue See related issues\n",
"list (or ls, or l) List available mirror sites and supported targets",
"list mirror/target List available mirror sites or supported targets",
"list os/lang/ware List supported OS/Programming Language/Software\n",
"measure <target> Measure velocity of all sources of <target>",
"cesu <target> \n",
"list <target> View available sources and supporting features for <target>",
"get <target> View the current source usage for <target>\n",
"set <target> Change source, select the fastest source by automatic speed measurement",
"set <target> first Change source, select the fastest source measured by the maintenance team",
"set <target> <mirror> Change source, specify a mirror site (Via list <target>)",
"set <target> https://url Change source, using user-defined source URL",
"reset <target> Reset source to the upstream's default\n",
"Options:",
"-dry Dry Run. Simulate the source changing process, command only prints, not run",
"-ipv6 Speed measurement using IPv6",
"-local Change source only for this project rather than globally (Via ls <target>)",
"-en(glish) Output in English\n",
"Maintain: <" Chsrc_Maintain_URL ">"
}; };
@ -285,8 +318,15 @@ cli_print_help ()
say (xy_strjoin (3, "chsrc: Change Source (GPLv3+) ", say (xy_strjoin (3, "chsrc: Change Source (GPLv3+) ",
purple (Chsrc_Banner_Version), " by RubyMetric")); purple (Chsrc_Banner_Version), " by RubyMetric"));
br(); br();
for (int i=0; i<xy_arylen (Chsrc_Usage); i++)
if (CliOpt_InEnglish)
{ {
for (int i=0; i<xy_arylen (Chsrc_Usage_English); i++)
say (Chsrc_Usage_English[i]);
}
else
{
for (int i=0; i<xy_arylen (Chsrc_Usage); i++)
say (Chsrc_Usage[i]); say (Chsrc_Usage[i]);
} }
} }
@ -332,7 +372,7 @@ iterate_targets_ (const char ***array, size_t size, const char *input, const cha
alias = target[k]; alias = target[k];
while (NULL!=alias) while (NULL!=alias)
{ {
if (xy_streql(input, alias)) if (xy_streql (input, alias))
{ {
matched = 1; break; matched = 1; break;
} }
@ -349,10 +389,13 @@ iterate_targets_ (const char ***array, size_t size, const char *input, const cha
return false; return false;
} }
do { do
{
k++; k++;
alias = target[k]; alias = target[k];
} while (NULL!=alias); }
while (NULL!=alias);
*target_info = target + k + 1; *target_info = target + k + 1;
return true; return true;
} }
@ -446,11 +489,20 @@ main (int argc, char const *argv[])
int cli_arg_Mirror_pos = cli_arg_Target_pos + 1; int cli_arg_Mirror_pos = cli_arg_Target_pos + 1;
const char *target = NULL; const char *target = NULL;
/**
// chsrc set -ipv6 target mirror * (1)
// 1 2 3 4 * chsrc set -local -en target mirror
// argc = 4 * 1 2 3 4 5
for (int i=2; i<=argc; i++) * argc = 5
*
* (2) i必须还是从1开始
* chsrc -en -h
* 1 2
*
* argc = 2
*/
/* 从第一个参数遍历到最后一个参数 */
for (int i=1; i<=argc; i++)
{ {
if (xy_str_start_with (argv[i], "-")) if (xy_str_start_with (argv[i], "-"))
{ {
@ -471,6 +523,12 @@ main (int argc, char const *argv[])
CliOpt_DryRun = true; CliOpt_DryRun = true;
chsrc_log (bdyellow ("**开启Dry Run模式模拟换源过程(跳过测速),命令仅打印并不运行**\n")); chsrc_log (bdyellow ("**开启Dry Run模式模拟换源过程(跳过测速),命令仅打印并不运行**\n"));
} }
else if (xy_streql (argv[i], "-h")
|| xy_streql (argv[i], "-help")
|| xy_streql (argv[i], "--help"))
{
command = "help"; /* 交到下方处理 */
}
else else
{ {
chsrc_error (xy_2strjoin ("未识别的命令行选项 ", argv[i])); return 1; chsrc_error (xy_2strjoin ("未识别的命令行选项 ", argv[i])); return 1;
@ -484,30 +542,31 @@ main (int argc, char const *argv[])
bool matched = false; bool matched = false;
/* chsrc help */ /* chsrc help */
if (xy_streql (command, "h") || if (xy_streql (command, "h")
xy_streql (command, "-h") || || xy_streql (command, "-h")
xy_streql (command, "help") || || xy_streql (command, "help")
xy_streql (command, "--help")) || xy_streql (command, "-help")
|| xy_streql (command, "--help"))
{ {
cli_print_help (); cli_print_help ();
return 0; return 0;
} }
/* chsrc -v */ /* chsrc -v */
else if (xy_streql (command, "-v") || else if (xy_streql (command, "-v")
xy_streql (command, "-version") || || xy_streql (command, "-version")
xy_streql (command, "--version")|| || xy_streql (command, "--version")
xy_streql (command, "ver") || || xy_streql (command, "ver")
xy_streql (command, "version")) || xy_streql (command, "version"))
{ {
cli_print_version (); cli_print_version ();
return 0; return 0;
} }
/* chsrc list */ /* chsrc list */
else if (xy_streql (command, "list") || else if (xy_streql (command, "list")
xy_streql (command, "l") || || xy_streql (command, "l")
xy_streql (command, "ls")) || xy_streql (command, "ls"))
{ {
if (argc < cli_arg_Target_pos) if (argc < cli_arg_Target_pos)
{ {
@ -547,12 +606,12 @@ main (int argc, char const *argv[])
/* chsrc measure */ /* chsrc measure */
else if (xy_streql (command, "measure") || else if (xy_streql (command, "measure")
xy_streql (command, "mea") || || xy_streql (command, "mea")
xy_streql (command, "m") || || xy_streql (command, "m")
xy_streql (command, "cesu") || || xy_streql (command, "cesu")
xy_streql (command, "ce") || || xy_streql (command, "ce")
xy_streql (command, "c")) || xy_streql (command, "c"))
{ {
if (argc < cli_arg_Target_pos) if (argc < cli_arg_Target_pos)
{ {
@ -567,8 +626,8 @@ main (int argc, char const *argv[])
/* chsrc get */ /* chsrc get */
else if (xy_streql (command, "get") || else if (xy_streql (command, "get")
xy_streql (command, "g")) || xy_streql (command, "g"))
{ {
if (argc < cli_arg_Target_pos) if (argc < cli_arg_Target_pos)
{ {
@ -582,8 +641,8 @@ main (int argc, char const *argv[])
} }
/* chsrc set */ /* chsrc set */
else if (xy_streql (command, "set") || else if (xy_streql (command, "set")
xy_streql (command, "s")) || xy_streql (command, "s"))
{ {
if (argc < cli_arg_Target_pos) if (argc < cli_arg_Target_pos)
{ {
@ -604,9 +663,9 @@ main (int argc, char const *argv[])
} }
/* chsrc reset */ /* chsrc reset */
else if (xy_streql (command, "reset") || else if (xy_streql (command, "reset")
xy_streql (command, "rest") || || xy_streql (command, "rest")
xy_streql (command, "r")) || xy_streql (command, "r"))
{ {
if (argc < cli_arg_Target_pos) if (argc < cli_arg_Target_pos)
{ {
@ -621,10 +680,10 @@ main (int argc, char const *argv[])
} }
/* chsrc issue */ /* chsrc issue */
else if (xy_streql (command, "issue") || else if (xy_streql (command, "issue")
xy_streql (command, "issues") || || xy_streql (command, "issues")
xy_streql (command, "isue") || || xy_streql (command, "isue")
xy_streql (command, "i")) || xy_streql (command, "i"))
{ {
cli_print_issues (); cli_print_issues ();
return 0; return 0;