151 lines
5.4 KiB
C++
151 lines
5.4 KiB
C++
#include "cmd_parse.h"
|
|
#include "logic.h"
|
|
#include <Poco/File.h>
|
|
|
|
void CPackBinaryCmd::initialize(Poco::Util::Application& self)
|
|
{
|
|
ServerApplication::initialize(self);
|
|
}
|
|
|
|
void CPackBinaryCmd::uninitialize()
|
|
{
|
|
ServerApplication::uninitialize();
|
|
}
|
|
|
|
void CPackBinaryCmd::defineOptions(Poco::Util::OptionSet& options)
|
|
{
|
|
ServerApplication::defineOptions(options);
|
|
options.addOption(Poco::Util::Option("help", "h", "Help Message")
|
|
.required(false)
|
|
.repeatable(false)
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleHelp)));
|
|
|
|
options.addOption(Poco::Util::Option("ico", "i", "ico_file")
|
|
.required(false)
|
|
.repeatable(false)
|
|
.argument("ico_file's full path")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
options.addOption(Poco::Util::Option("file", "f", "binary_file")
|
|
.required(false)
|
|
.repeatable(false)
|
|
// argument 就是 require 什么东西的具体介绍。
|
|
.argument("binary_file's full path")
|
|
.binding("nobinding")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
options.addOption(Poco::Util::Option("category", "c", "category name")
|
|
.required(false)
|
|
.repeatable(false)
|
|
.argument("category name")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
|
|
options.addOption(Poco::Util::Option("purpose", "p", "purpose dir")
|
|
.required(false)
|
|
.repeatable(false)
|
|
.argument("purpose dir")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
options.addOption(Poco::Util::Option("mode", "m", "mode name")
|
|
.required(false)
|
|
.repeatable(false)
|
|
.argument("mode name")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
options.addOption(Poco::Util::Option("ext", "e", "dirs_when_search_lib")
|
|
.required(false)
|
|
.repeatable(true)
|
|
.argument("dirs_when_search_lib")
|
|
.callback(Poco::Util::OptionCallback<CPackBinaryCmd>(
|
|
this, &CPackBinaryCmd::handleInput)));
|
|
}
|
|
|
|
void CPackBinaryCmd::handleHelp(const std::string& name,
|
|
const std::string& value)
|
|
{
|
|
std::string introduce = ""
|
|
"PackBinary options:\n"
|
|
" -ico <ico_file> 安装快捷方式时的ico文件路径。\n"
|
|
" -file <binary_file> 二进制文件。\n"
|
|
" -include <search_lib_dir> 搜索的库路径。\n"
|
|
" -category <category name> 分类名称。\n"
|
|
" -mode <mode name> 执行方式(0-打包,1-安装)。"
|
|
"";
|
|
std::cout << introduce << std::endl;
|
|
stopOptionsProcessing();
|
|
}
|
|
|
|
void CPackBinaryCmd::handleInput(const std::string& name,
|
|
const std::string& value)
|
|
{
|
|
if (name == "ico") {
|
|
result_.ico = value;
|
|
return;
|
|
}
|
|
if (name == "file") {
|
|
result_.binary = value;
|
|
return;
|
|
}
|
|
if (name == "purpose") {
|
|
result_.purpose_dir = value;
|
|
return;
|
|
}
|
|
if (name == "ext") {
|
|
result_.lib_dirs.push_back(value);
|
|
return;
|
|
}
|
|
if (name == "mode") {
|
|
result_.mode = value.empty() ? -1 : std::stoi(value);
|
|
return;
|
|
}
|
|
if (name == "category") {
|
|
result_.category = value;
|
|
return;
|
|
}
|
|
}
|
|
|
|
int CPackBinaryCmd::main(const std::vector<std::string>& args)
|
|
{
|
|
if (!validCheck()) {
|
|
return Application::EXIT_CONFIG;
|
|
}
|
|
CMainLogic mainLogic;
|
|
if (mainLogic.run(result_)) {
|
|
return Application::EXIT_OK;
|
|
} else {
|
|
return Application::EXIT_SOFTWARE;
|
|
}
|
|
}
|
|
|
|
bool CPackBinaryCmd::validCheck()
|
|
{
|
|
std::cout << "ico:" << result_.ico << std::endl;
|
|
std::cout << "file:" << result_.binary << std::endl;
|
|
std::cout << "mode:" << result_.mode << std::endl;
|
|
std::cout << "category:" << result_.category << std::endl;
|
|
std::cout << "include, size = " << result_.lib_dirs.size() << std::endl;
|
|
|
|
for (const auto& item : result_.lib_dirs) {
|
|
std::cout << ">>" << item << std::endl;
|
|
}
|
|
|
|
switch (result_.mode) {
|
|
case 0: {
|
|
Poco::File file(result_.binary);
|
|
if (!file.exists()) {
|
|
std::cout << "binary file not exist." << std::endl;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
case 1: {
|
|
return true;
|
|
}
|
|
default:
|
|
std::cout << "不合法的mode内容。" << std::endl;
|
|
return false;
|
|
}
|
|
}
|