This commit is contained in:
codeboss 2024-10-04 13:12:16 +08:00
parent 48af8723ef
commit 37e3119934
8 changed files with 62 additions and 12 deletions

View File

@ -113,6 +113,17 @@ MatchMode::MatchMode(int mode_code, const QString& mode)
*/ */
MatchMode& MatchMode::operator<<(std::shared_ptr<IArgvPack> unit) { MatchMode& MatchMode::operator<<(std::shared_ptr<IArgvPack> unit) {
if(unit->paramType() == ParamType::FloatParam){
auto unit_in = std::dynamic_pointer_cast<__FloatArgvImpls>(unit);
for (auto& u_exist : args_mode) {
if (u_exist->paramType() == ParamType::FloatParam) {
auto u_cast = std::dynamic_pointer_cast<__FloatArgvImpls>(u_exist);
if (u_cast->bindKey() == unit_in->bindKey())
throw new std::exception("重复设置选项");
}
}
}
args_mode << unit; args_mode << unit;
return *this; return *this;
} }
@ -221,7 +232,7 @@ std::shared_ptr<IArgvPack> MatchMode::getUnitViaInitIndex(int pos) {
return args_mode[pos]; return args_mode[pos];
} }
QString ArgsParser::helpDoc() const { QString ArgsParser::helperDoc() const {
QString help_string; QString help_string;
for (auto& mode : this->match_modes) { for (auto& mode : this->match_modes) {
help_string += "Usage:" + mode->usageString() + "\n"; help_string += "Usage:" + mode->usageString() + "\n";

View File

@ -199,7 +199,7 @@ namespace args_parse {
QList<std::shared_ptr<MatchMode>> match_modes; QList<std::shared_ptr<MatchMode>> match_modes;
public: public:
QString helpDoc() const; QString helperDoc() const;
ArgsParser& operator<<(std::shared_ptr<MatchMode> mode); ArgsParser& operator<<(std::shared_ptr<MatchMode> mode);

View File

@ -61,15 +61,25 @@
<PropertyGroup Label="UserMacros" /> <PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<TargetName>StoryPresent</TargetName> <TargetName>StoryPresent</TargetName>
<IncludePath>$(SolutionDir)ArgsParser;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<TargetName>$(ProjectName)</TargetName> <TargetName>$(ProjectName)</TargetName>
<IncludePath>$(SolutionDir)ArgsParser;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
</PropertyGroup> </PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link /> <Link />
<Link>
<AdditionalDependencies>ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link /> <Link />
<Link>
<AdditionalDependencies>ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile> <ClCompile>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>--graph --path D:\CustomNovel</LocalDebuggerCommandArguments> <LocalDebuggerCommandArguments>--help</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor> <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

View File

@ -205,9 +205,7 @@ QList<std::shared_ptr<DAGOrderHelper>> DAGGraph::tidy_graph_nodes() {
nodes_temp[node->bindPoint().name()] = std::make_shared<DAGOrderHelper>(node); nodes_temp[node->bindPoint().name()] = std::make_shared<DAGOrderHelper>(node);
} }
QList<std::shared_ptr<DAGOrderHelper>> temp_array; QList<std::shared_ptr<DAGOrderHelper>> temp_array(nodes_temp.values());
temp_array.append(nodes_temp.values());
for (auto node : this->graph_inst.values()) { for (auto node : this->graph_inst.values()) {
for (auto next : node->nextNodes()) { for (auto next : node->nextNodes()) {
auto node_links = QList<std::shared_ptr<DAGOrderHelper>>{ auto node_links = QList<std::shared_ptr<DAGOrderHelper>>{

View File

@ -3,13 +3,44 @@
#include "xast_parse.h" #include "xast_parse.h"
#include "dag_present.h" #include "dag_present.h"
#include "view_present.h" #include "view_present.h"
#include <argsparser.h>
#include <QDebug> #include <QDebug>
#include <qloggingcategory.h> #include <QMessageBox>
#include <QTextEdit>
#include <QtWidgets/QApplication> #include <QtWidgets/QApplication>
using namespace args_parse;
using namespace std;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
ArgsParser cmdrec;
auto help_mode = std::make_shared<MatchMode>(0x000au, u8"打印帮助文档");
cmdrec << help_mode;
(*help_mode) << std::make_shared<IndexParam>(u8"StoryPresent", u8"程序名") << make_shared<FloatOption>(u8"help", u8"打印帮助文档");
auto rst = cmdrec.parse(argc, argv);
QTextEdit msg;
msg.setReadOnly(true);
if (!rst) {
msg.setWindowTitle(u8"参数输入错误");
msg.setPlainText(cmdrec.helperDoc());
msg.show();
}
else {
switch (rst->modeCode()) {
case 0x000au:
msg.setWindowTitle(u8"帮助信息");
msg.setPlainText(cmdrec.helperDoc());
msg.show();
break;
default:
break;
}
}
return a.exec(); return a.exec();
} }

View File

@ -40,12 +40,12 @@ int main(int argc, char *argv[])
auto rst = entry_parser.parse(argc, argv); auto rst = entry_parser.parse(argc, argv);
if (!rst) { if (!rst) {
qDebug().noquote() << u8"命令行参数错误"; qDebug().noquote() << u8"命令行参数错误";
qDebug().noquote() << entry_parser.helpDoc(); qDebug().noquote() << entry_parser.helperDoc();
return 0; return 0;
} }
if (rst->modeCode() == 0x000au) { if (rst->modeCode() == 0x000au) {
qDebug().noquote() << entry_parser.helpDoc(); qDebug().noquote() << entry_parser.helperDoc();
} }

View File

@ -41,7 +41,7 @@ int main(int argc, char* argv[]) {
auto p_result = args_parser.parse(argc, argv); auto p_result = args_parser.parse(argc, argv);
if (!p_result) { if (!p_result) {
qDebug().noquote() << u8"命令行参数错误!"; qDebug().noquote() << u8"命令行参数错误!";
qDebug().noquote() << args_parser.helpDoc(); qDebug().noquote() << args_parser.helperDoc();
} }
else { else {
switch (p_result->modeCode()) { switch (p_result->modeCode()) {
@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
}break; }break;
case 0xAu: case 0xAu:
default: default:
qDebug().noquote() << args_parser.helpDoc(); qDebug().noquote() << args_parser.helperDoc();
break; break;
} }
} }