diff --git a/.vscode/settings.json b/.vscode/settings.json index c30b172..83a4bb1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ ], "visualizerFile": "${workspaceRoot}/.vscode/qt5.natvis", "args": [ - "-a", "106.14.150.219:9898" + "-h" ] }, "cmake.environment": { @@ -141,6 +141,7 @@ "expected": "cpp", "numbers": "cpp", "semaphore": "cpp", - "span": "cpp" + "span": "cpp", + "text_encoding": "cpp" } } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 92726be..d381627 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_SYSTEM_NAME MATCHES "Windows") MESSAGE(STATUS "Add MinGW Param.") add_compile_options(-finput-charset=utf-8) add_compile_options(-fexec-charset=gbk) + add_compile_options(-Wa,-mbig-obj) endif() set(CMAKE_DEBUG_POSTFIX "d") diff --git a/client/client.h b/client/client.h index d7c1e6a..d7f4de6 100644 --- a/client/client.h +++ b/client/client.h @@ -88,6 +88,7 @@ class CFileOpr public: CFileOpr(); ~CFileOpr(); + public: static std::vector get_file_list(const std::string& input); }; \ No newline at end of file diff --git a/client/config.h b/client/config.h index 54963df..bfedfe2 100644 --- a/client/config.h +++ b/client/config.h @@ -17,6 +17,7 @@ struct CmdParam { std::string appendValue; bool showValue{false}; long use_config{-1}; + bool parsed{false}; }; class CServerConfig diff --git a/client/main.cpp b/client/main.cpp index 4baf90a..88f6d7a 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -8,7 +8,7 @@ std::shared_ptr g_Logger = nullptr; std::shared_ptr g_Config = nullptr; -bool parse_cmd(int argc, char** argv, CmdParam& param) +int parse_cmd(int argc, char** argv, CmdParam& param) { std::string intro("transmc cmd introduce."); CLI::App app(intro); @@ -17,14 +17,20 @@ bool parse_cmd(int argc, char** argv, CmdParam& param) app.add_option("-a, --append", param.appendValue, "添加服务器地址组(地址格式:127.0.0.1:9898)"); app.add_flag("-s, --show", param.showValue, "查看服务器地址组"); app.add_option("-r, --remove", param.removeValue, "移除服务器地址组(值为使用--show中显示的序号)"); + + if (argc == 1) { + std::cout << app.help() << std::endl; + return 0; + } + // 这里的 CLI11_PARSE 在程序没有输入或者仅输入--help(-h)时,会直接返回,后面代码都不会执行。 + // 当有自定义的参数被输入时,后面代码会执行。 try { CLI11_PARSE(app, argc, argv); - return true; } catch (const CLI::ParseError& e) { - std::cerr << "Error parsing command line: " << e.what() << std::endl; - return false; + return app.exit(e); } - return false; + param.parsed = true; + return 0; } bool exec_cmd(const CmdParam& param, bool& run) @@ -49,7 +55,6 @@ bool exec_cmd(const CmdParam& param, bool& run) g_Logger->error("append and remove can't simultaneous operate!"); return false; } - // 如果是移除 if (!param.appendValue.empty()) { std::regex rg(R"(([^:]+):(\d+))"); std::smatch match; @@ -68,10 +73,10 @@ bool exec_cmd(const CmdParam& param, bool& run) } if (!param.removeValue.empty()) { if (!g_Config->remove_ini(std::stol(param.removeValue))) { - g_Logger->error("remove {} failed, please check!", param.removeValue); + g_Logger->error("remove config num=[{}] failed, please check!", param.removeValue); return false; } - g_Logger->info("remove {} success!", param.removeValue); + g_Logger->info("remove config num=[{}] success!", param.removeValue); return true; } g_Logger->error("not matched!", param.removeValue); @@ -89,36 +94,29 @@ int main(int argc, char* argv[]) bool run = false; CmdParam param; - if (!parse_cmd(argc, argv, param)) { - g_Logger->error("parse cmd failed!"); - return -1; - } - - if (param.appendValue.empty() && param.removeValue.empty() && param.showValue == false && - param.use_config == -1) { - g_Logger->warn("Use --help To Get How To Use."); + parse_cmd(argc, argv, param); + if (!param.parsed) { return 0; } - if (!exec_cmd(param, run)) { g_Logger->error("exec_cmd failed!"); return -1; } - if (!run) { return 0; } - g_Logger->info("Configure At {} under {} on {}", VERSION_BUILD_DATE, VERSION_GIT_HASH, - VERSION_GIT_BRANCH); std::vector set; if (!g_Config->read_ini(set)) { return -1; } TransmSet use; if (!g_Config->get_ini(set, param.use_config, use)) { + g_Logger->error("Not found config by num:[{}]", param.use_config); return -1; } + g_Logger->info("Configure At {} under {} on {}", VERSION_BUILD_DATE, VERSION_GIT_HASH, + VERSION_GIT_BRANCH); g_Logger->info("use ip:[{}], port:[{}]", use.ip, use.port); CClient client(g_Logger); client.run(use.ip, std::to_string(use.port));