Compare commits

...

2 Commits

Author SHA1 Message Date
codeboss f0ed01bff6 命令行参数改进 2024-06-05 12:12:31 +08:00
codeboss 221c3757b1 some-update 2024-06-05 08:27:34 +08:00
2 changed files with 38 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerWorkingDirectory>$(SolutionDir)$(Platform)\$(Configuration)\</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommandArguments>-path "D:\手作小说\科学+修仙+创造世界"</LocalDebuggerCommandArguments>
<LocalDebuggerCommandArguments>--path "D:\手作小说\科学+修仙+创造世界"</LocalDebuggerCommandArguments>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2024-06-04T12:14:58.9515031Z</QtLastBackgroundBuild>

View File

@ -29,25 +29,52 @@ std::function<void(std::shared_ptr<const ast_gen::ElementAccess>, int)> tnode_pr
tnode_print(c_n, intend + 1);
}
};
/*
* nsc --help
* nsc [opts] --path path-to-dir
* opts:
* -p print-struct
* -s service
*/
int main(int argc, char* argv[]) {
QCoreApplication a(argc, argv);
if (argc != 3 || strcmp(argv[1], "-path")) {
QStringList args;
for (int idx = 0; idx < argc; idx++) {
args += QString::fromLocal8Bit(argv[idx]);
}
// 帮助特殊用法
if (args.contains(u8"--help")) {
std::cout << "nsc(WsNovelStoryCompiler£º¹ÊÊÂÏß±àÒëÆ÷)" << std::endl;
std::cout << "°æ±¾£ºV1.00" << std::endl;
std::cout << "版本V1.0.0" << std::endl;
std::cout << "nsc -path path-to-dir" << std::endl;
exit(0);
}
auto sdir = QDir::current();
if (argc >= 3 && !strcmp(argv[1], "-path")) {
auto tdir = QDir(QString::fromLocal8Bit(argv[2]));
if (tdir.exists())
sdir = tdir;
auto source_dir = QDir::current();
auto index = args.indexOf(u8"--path");
if (index < 0) {
std::cout << "参数错误:必须指定 --path 参数" << endl;
exit(1);
}
if (index + 1 >= args.size()) {
std::cout << "参数错误:--path 后面应该续接story文件的父文件夹路径。" << std::endl;
exit(1);
}
else {
auto tdir = QDir(args[index+1]);
if (tdir.exists()) {
source_dir = tdir;
}
else {
std::cout << "参数错误传入的story文件父文件夹路径无效。"<< std::endl;
exit(1);
}
}
auto files = sdir.entryInfoList(QStringList() << "*.story");
auto files = source_dir.entryInfoList(QStringList() << "*.story");
if (files.size()) {
try {
auto parser = std::make_shared<NovelParser>();
@ -126,7 +153,7 @@ int main(int argc, char* argv[]) {
body.appendChild(dom_storyline);
auto lines = tool.storyline_defines.values();
std::sort(lines.begin(), lines.end(), [](std::shared_ptr<printer::StoryLine> a, std::shared_ptr<printer::StoryLine> b)->bool{
std::sort(lines.begin(), lines.end(), [](std::shared_ptr<printer::StoryLine> a, std::shared_ptr<printer::StoryLine> b)->bool {
auto a_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(a->accessPeers()->element());
auto b_elm = std::dynamic_pointer_cast<const example_novel::StoryDefine>(b->accessPeers()->element());
return a_elm->sort() < b_elm->sort();