合并pr(#661): 减少unsport code打印,新增git信息获取

(cherry picked from commit 47f2f5b349)
This commit is contained in:
monktan
2020-12-29 11:36:06 +08:00
committed by xiongziliang
parent d37607026f
commit 3ddc14d35d
6 changed files with 72 additions and 8 deletions

View File

@@ -8,10 +8,8 @@
* may be found in the AUTHORS file in the root of the source tree.
*/
#include <map>
#include <signal.h>
#include <iostream>
#include "Util/MD5.h"
#include "Util/File.h"
#include "Util/logger.h"
#include "Util/SSLBox.h"
@@ -28,6 +26,10 @@
#include "WebApi.h"
#include "WebHook.h"
#if defined(ENABLE_VERSION)
#include "Version.h"
#endif
#if !defined(_WIN32)
#include "System.h"
#endif//!defined(_WIN32)
@@ -146,10 +148,21 @@ public:
false,/*该选项是否必须赋值如果没有默认值且为ArgRequired时用户必须提供该参数否则将抛异常*/
"启动事件触发线程数",/*该选项说明文字*/
nullptr);
#if defined(ENABLE_VERSION)
(*_parser) << Option('v', "version", Option::ArgNone, nullptr, false, "显示版本号",
[](const std::shared_ptr<ostream> &stream, const string &arg) -> bool {
//版本信息
*stream << "编译日期: " << build_time << std::endl;
*stream << "当前git分支: " << branch_name << std::endl;
*stream << "当前git hash值: " << commit_hash << std::endl;
throw ExitException();
});
#endif
}
virtual ~CMD_main() {}
virtual const char *description() const {
~CMD_main() override{}
const char *description() const override{
return "主程序命令参数";
}
};
@@ -201,6 +214,8 @@ int start_main(int argc,char *argv[]) {
CMD_main cmd_main;
try {
cmd_main.operator()(argc, argv);
} catch (ExitException &ex) {
return 0;
} catch (std::exception &ex) {
cout << ex.what() << endl;
return -1;