mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-01 12:23:41 +08:00
Redefine exit code
This commit is contained in:
parent
5f8c0a6ff3
commit
d4ecd8dc1e
|
@ -52,11 +52,13 @@ bool CliOpt_NoColor = false;
|
|||
* 3. 最终效果本质由第三方软件决定,如 poetry 默认实现的就是项目级的换源
|
||||
*/
|
||||
|
||||
#define Exit_UserCause 1
|
||||
#define Exit_Unsupported 2
|
||||
#define Exit_MatinerIssue 3
|
||||
#define Exit_FatalBug 4
|
||||
#define Exit_FatalUnkownError 5
|
||||
#define Exit_OK 0
|
||||
#define Exit_Fatal 1
|
||||
#define Exit_Unknown 2
|
||||
#define Exit_Unsupported 3
|
||||
#define Exit_UserCause 4
|
||||
#define Exit_MaintainerCause 5
|
||||
#define Exit_ExternalError 6
|
||||
|
||||
#define chsrc_log(str) xy_log(App_Name,str)
|
||||
#define chsrc_succ(str) xy_succ(App_Name,str)
|
||||
|
@ -322,7 +324,7 @@ query_mirror_exist (SourceInfo *sources, size_t size, char *target, char *input)
|
|||
char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 ";
|
||||
char *msg2 = CliOpt_InEnglish ? " doesn't have any source available, please contact the maintainer" : " 无任何可用源,请联系维护者";
|
||||
chsrc_error (xy_strjoin (3, msg1, target, msg2));
|
||||
exit (Exit_MatinerIssue);
|
||||
exit (Exit_MaintainerCause);
|
||||
}
|
||||
|
||||
if (2==size)
|
||||
|
@ -609,7 +611,7 @@ select_mirror_autoly (SourceInfo *sources, size_t size, const char *target_name)
|
|||
char *msg1 = CliOpt_InEnglish ? "Currently " : "当前 ";
|
||||
char *msg2 = CliOpt_InEnglish ? "No any source, please contact maintainers: chsrc issue" : " 无任何可用源,请联系维护者: chsrc issue";
|
||||
chsrc_error (xy_strjoin (3, msg1, target_name, msg2));
|
||||
exit (Exit_MatinerIssue);
|
||||
exit (Exit_MaintainerCause);
|
||||
}
|
||||
|
||||
if (CliOpt_DryRun)
|
||||
|
@ -766,9 +768,9 @@ confirm_source (SourceInfo *source)
|
|||
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" : \
|
||||
"该源URL不存在,请向开发团队提交bug";
|
||||
"该源URL不存在,请向维护团队提交bug";
|
||||
chsrc_error (msg);
|
||||
exit (Exit_FatalBug);
|
||||
exit (Exit_MaintainerCause);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -992,7 +994,7 @@ chsrc_run (const char *cmd, int run_option)
|
|||
{
|
||||
char *msg = CliOpt_InEnglish ? "Fatal error, forced end" : "关键错误,强制结束";
|
||||
chsrc_error (msg);
|
||||
exit (Exit_FatalUnkownError);
|
||||
exit (Exit_ExternalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -584,7 +584,7 @@ main (int argc, char const *argv[])
|
|||
if (0==argc)
|
||||
{
|
||||
cli_print_help ();
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
const char *command = argv[1];
|
||||
|
@ -648,7 +648,7 @@ main (int argc, char const *argv[])
|
|||
else
|
||||
{
|
||||
char *msg = CliOpt_InEnglish ? "Unknown option: " : "未识别的命令行选项 ";
|
||||
chsrc_error (xy_2strjoin (msg, argv[i])); return 1;
|
||||
chsrc_error (xy_2strjoin (msg, argv[i])); return Exit_Unknown;
|
||||
}
|
||||
cli_arg_Target_pos++;
|
||||
cli_arg_Mirror_pos++;
|
||||
|
@ -675,7 +675,7 @@ main (int argc, char const *argv[])
|
|||
|| xy_streql (command, "--help"))
|
||||
{
|
||||
cli_print_help ();
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
/* chsrc -v */
|
||||
|
@ -686,7 +686,7 @@ main (int argc, char const *argv[])
|
|||
|| xy_streql (command, "version"))
|
||||
{
|
||||
cli_print_version ();
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
/* chsrc list */
|
||||
|
@ -705,29 +705,29 @@ main (int argc, char const *argv[])
|
|||
target = argv[cli_arg_Target_pos];
|
||||
if (xy_streql (target, "mirrors") || xy_streql (target, "mirror"))
|
||||
{
|
||||
cli_print_available_mirrors (); return 0;
|
||||
cli_print_available_mirrors (); return Exit_OK;
|
||||
}
|
||||
else if (xy_streql (target, "targets") || xy_streql (target, "target"))
|
||||
{
|
||||
cli_print_supported_targets (); return 0;
|
||||
cli_print_supported_targets (); return Exit_OK;
|
||||
}
|
||||
else if (xy_streql (target, "os"))
|
||||
{
|
||||
cli_print_supported_os (); return 0;
|
||||
cli_print_supported_os (); return Exit_OK;
|
||||
}
|
||||
else if (xy_streql (target, "lang") || xy_streql (target, "pl") || xy_streql (target, "language"))
|
||||
{
|
||||
cli_print_supported_pl(); return 0;
|
||||
cli_print_supported_pl(); return Exit_OK;
|
||||
}
|
||||
else if (xy_streql (target, "ware") || xy_streql (target, "software"))
|
||||
{
|
||||
cli_print_supported_wr (); return 0;
|
||||
cli_print_supported_wr (); return Exit_OK;
|
||||
}
|
||||
|
||||
matched = get_target (target, TargetOp_List_Config, NULL);
|
||||
if (!matched) goto not_matched;
|
||||
}
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
#define MSG_EN_USE_LIST_TARGETS "Use `chsrc list targets` to see all supported targets"
|
||||
|
@ -746,13 +746,13 @@ main (int argc, char const *argv[])
|
|||
char *msg = CliOpt_InEnglish ? "Please provide the target name you want to measure. " MSG_EN_USE_LIST_TARGETS
|
||||
: "请您提供想要测速源的目标名。" MSG_CN_USE_LIST_TARGETS;
|
||||
chsrc_error (msg);
|
||||
return 1;
|
||||
return Exit_Unknown;
|
||||
}
|
||||
ProgMode_CMD_Measure = true;
|
||||
target = argv[cli_arg_Target_pos];
|
||||
matched = get_target (target, TargetOp_Measure_Source, NULL);
|
||||
if (!matched) goto not_matched;
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -765,12 +765,12 @@ main (int argc, char const *argv[])
|
|||
char *msg = CliOpt_InEnglish ? "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 1;
|
||||
return Exit_Unknown;
|
||||
}
|
||||
target = argv[cli_arg_Target_pos];
|
||||
matched = get_target (target, TargetOp_Get_Source, NULL);
|
||||
if (!matched) goto not_matched;
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
/* chsrc set */
|
||||
|
@ -782,7 +782,7 @@ main (int argc, char const *argv[])
|
|||
char *msg = CliOpt_InEnglish ? "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 1;
|
||||
return Exit_Unknown
|
||||
}
|
||||
|
||||
target = argv[cli_arg_Target_pos];
|
||||
|
@ -794,7 +794,7 @@ main (int argc, char const *argv[])
|
|||
|
||||
matched = get_target (target, TargetOp_Set_Source, mirrorCode_or_url);
|
||||
if (!matched) goto not_matched;
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
/* chsrc reset */
|
||||
|
@ -807,14 +807,14 @@ main (int argc, char const *argv[])
|
|||
char *msg = CliOpt_InEnglish ? "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 1;
|
||||
return Exit_Unknown;
|
||||
}
|
||||
|
||||
ProgMode_CMD_Reset = true;
|
||||
target = argv[cli_arg_Target_pos];
|
||||
matched = get_target (target, TargetOp_Reset_Source, NULL);
|
||||
if (!matched) goto not_matched;
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
/* chsrc issue */
|
||||
|
@ -824,7 +824,7 @@ main (int argc, char const *argv[])
|
|||
|| xy_streql (command, "i"))
|
||||
{
|
||||
cli_print_issues ();
|
||||
return 0;
|
||||
return Exit_OK;
|
||||
}
|
||||
|
||||
else
|
||||
|
@ -832,7 +832,7 @@ main (int argc, char const *argv[])
|
|||
char *msg1 = CliOpt_InEnglish ? "Unknown command `" : "不支持的命令 ";
|
||||
char *msg2 = CliOpt_InEnglish ? "`. Use `chsrc help` to view usage" : ". 请使用 chsrc help 查看使用方式";
|
||||
chsrc_error (xy_strjoin (3, msg1, command, msg2));
|
||||
return 1;
|
||||
return Exit_Unknown;
|
||||
}
|
||||
|
||||
not_matched:
|
||||
|
@ -841,6 +841,6 @@ not_matched:
|
|||
char *msg = CliOpt_InEnglish ? "Unknown target. " MSG_EN_USE_LIST_TARGETS
|
||||
: "暂不支持的换源目标。" MSG_CN_USE_LIST_TARGETS;
|
||||
chsrc_error (msg);
|
||||
return 1;
|
||||
return Exit_Unknown;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user