diff --git a/include/chsrc.h b/include/chsrc.h index e651db8..dbe6906 100644 --- a/include/chsrc.h +++ b/include/chsrc.h @@ -15,6 +15,11 @@ #define App_Name "chsrc" +#define Exit_UserCause 1 +#define Exit_Unsupported 2 +#define Exit_MatinerIssue 3 +#define Exit_FatalError 4 + #define chsrc_log(str) xy_log(App_Name,str) #define chsrc_succ(str) xy_succ(App_Name,str) #define chsrc_info(str) xy_info(App_Name,str) @@ -114,7 +119,7 @@ chsrc_ensure_program (char *prog_name) else { chsrc_error (xy_strjoin (3, "未找到 ", prog_name, " 命令,请检查是否存在")); - exit (1); + exit (Exit_UserCause); } } @@ -148,13 +153,13 @@ query_mirror_exist (SourceInfo *sources, size_t size, char *target, char *input) if (is_url (input)) { chsrc_error ("暂不支持对该软件使用用户自定义源,请联系开发者询问原因或请求支持"); - exit (1); + exit (Exit_Unsupported); } if (0==size || 1==size) { chsrc_error (xy_strjoin (3, "当前 ", target, " 无任何可用源,请联系维护者")); - exit (1); + exit (Exit_MatinerIssue); } if (2==size) @@ -192,7 +197,7 @@ query_mirror_exist (SourceInfo *sources, size_t size, char *target, char *input) { chsrc_error (xy_strjoin (3, "镜像站 ", input, " 不存在")); chsrc_error (xy_2strjoin ("查看可使用源,请使用 chsrc list ", target)); - exit (1); + exit (Exit_UserCause); } return idx; } @@ -312,7 +317,7 @@ auto_select_ (SourceInfo *sources, size_t size, const char *target) if (0==size || 1==size) { chsrc_error (xy_strjoin (3, "当前 ", target, " 无任何可用源,请联系维护者: chsrc issue")); - exit (1); + exit (Exit_MatinerIssue); } bool onlyone = false; @@ -323,7 +328,7 @@ auto_select_ (SourceInfo *sources, size_t size, const char *target) if (!exist_curl) { chsrc_error ("没有curl命令,无法测速"); - exit (1); + exit (Exit_UserCause); } double speeds[size]; @@ -428,12 +433,12 @@ chsrc_confirm_selection (SourceInfo *source) if (source_is_upstream (source) && source_has_empty_url (source)) { chsrc_error ("暂未对该软件实现重置"); - exit (2); + exit (Exit_Unsupported); } else if (source_has_empty_url (source)) { chsrc_error ("该源URL不存在,请向开发团队提交bug"); - exit (2); + exit (Exit_FatalError); } else { @@ -564,7 +569,7 @@ chsrc_ensure_root () } not_root: chsrc_error ("请在命令前使用 sudo 或切换为root用户来保证必要的权限"); - exit (1); + exit (Exit_UserCause); } diff --git a/src/chsrc.c b/src/chsrc.c index 400fce9..8c31f93 100644 --- a/src/chsrc.c +++ b/src/chsrc.c @@ -5,7 +5,7 @@ * Authors : Aoran Zeng * | Heng Guo <2085471348@qq.com> * Created on : <2023-08-28> - * Last modified : Same With Chsrc_Version + * Last modified : <2024-06-14> * * chsrc: Change Source —— 全平台通用命令行换源工具 * ------------------------------------------------------------*/ @@ -112,7 +112,7 @@ pl_python_check_cmd (char **prog, bool *pdm_exist) else { chsrc_error ("未找到 Python 相关命令,请检查是否存在"); - exit (1); + exit (Exit_UserCause); } } @@ -194,7 +194,7 @@ pl_nodejs_check_cmd (bool *npm_exist, bool *yarn_exist, bool *pnpm_exist) if (!*npm_exist && !*yarn_exist && !*pnpm_exist) { chsrc_error ("未找到 npm 或 yarn 或 pnpm 命令,请检查是否存在其一"); - exit (1); + exit (Exit_UserCause); } } @@ -387,7 +387,7 @@ pl_go_check_cmd () if (!exist) { chsrc_error ("未找到 go 相关命令,请检查是否存在"); - exit (1); + exit (Exit_UserCause); } } @@ -476,7 +476,7 @@ pl_java_check_cmd (bool *maven_exist, bool *gradle_exist) if (! *maven_exist && ! *gradle_exist) { chsrc_error ("maven 与 gradle 命令均未找到,请检查是否存在其一"); - exit (1); + exit (Exit_UserCause); } } @@ -882,7 +882,7 @@ ensure_apt_sourcelist (int debian_type) else { chsrc_error ("您的Debian版本过低(<10),暂不支持换源"); - exit (2); + exit (Exit_Unsupported); } } @@ -2239,7 +2239,7 @@ wr_anaconda_setsrc (char *option) if (!exist) { chsrc_error ("未找到 conda 命令,请检查是否存在"); - exit (1); + exit (Exit_UserCause); } chsrc_run ("conda config --set show_channel_urls yes"); }