This commit is contained in:
codeboss 2024-10-03 20:37:24 +08:00
parent aa9cdff7a4
commit 90b2323eb0
9 changed files with 254 additions and 55 deletions

View File

@ -74,8 +74,7 @@ __FloatArgvImpls::__FloatArgvImpls(const QString& key, const QString& means, boo
: __ArgvPackImpls(means, ParamType::FloatParam), key_name(key), optional_value(optional) { }
FloatOption::FloatOption(const QString& key, const QString& means, bool opt)
: __FloatArgvImpls(key, means, opt) {
}
: __FloatArgvImpls(key, means, opt) { }
QString args_parse::FloatOption::placeHolder(bool d) const {
if (optional() && d)
@ -89,8 +88,9 @@ int FloatOption::matchLenth() const {
bool FloatOption::parse(const QList<QString> args, int start) {
auto args_t = args[start];
setValue(args_t == bindKey());
return args_t == u8"--" + bindKey();
if (args_t == u8"--" + bindKey())
setValue(true);
return false;
}
MatchMode::MatchMode(int mode_code, const QString& mode)
@ -124,9 +124,18 @@ QString args_parse::MatchMode::explanString() const {
sections << QString(" Switch:");
for (auto& item : args_mode) {
if (item->paramType() == ParamType::IndexParam) {
sections << " " + item->placeHolder(false);
sections << " " + item->means();
}
}
for (auto& item : args_mode) {
if (item->paramType() == ParamType::FloatParam) {
sections << " " + item->placeHolder(false);
sections << " " + item->means();
}
}
return sections.join("\n");
}
@ -136,9 +145,6 @@ QString args_parse::MatchMode::explanString() const {
*/
bool MatchMode::parse(const QList<QString>& args, int argv_index, int parse_index) {
if (argv_index >= args.size())
return true;
// 获取模式匹配单元
auto parse_unit = args_mode[parse_index];
switch (parse_unit->paramType()) {
@ -151,18 +157,19 @@ bool MatchMode::parse(const QList<QString>& args, int argv_index, int parse_inde
case ParamType::FloatParam:// 浮动参数匹配
{
QList<shared_ptr<__FloatArgvImpls>> float_parsers;
for (auto& unit : args_mode) {
if (unit->paramType() == ParamType::FloatParam)
float_parsers << dynamic_pointer_cast<__FloatArgvImpls>(unit);
}
for (auto& unit : float_parsers) {
if (unit->matchLenth() + argv_index > args.size())
if (argv_index + unit->matchLenth() > args.size())
continue;
auto result = unit->parse(args, argv_index);
// 匹配成功
if (result)
// 继续下一个
if (parse(args, argv_index + unit->matchLenth(), parse_index + 1))
return true;
else if (!result && unit->optional())

View File

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

View File

@ -3,42 +3,13 @@
#include "xast_parse.h"
#include "dag_present.h"
#include "view_present.h"
#include <argsparser.h>
#include <QDebug>
#include <qloggingcategory.h>
#include <QtWidgets/QApplication>
int main(int argc, char* argv[]) {
QApplication a(argc, argv);
args_parse::ArgsParser entry_parser;
QList<std::shared_ptr<args_parse::IArgvPack>> args_mode;
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--help", "帮助选项");
entry_parser.loadMode(0x000au, args_mode);
args_mode.clear();
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
args_mode << std::make_shared<args_parse::FloatOption>(u8"--nsc", u8"调用编译功能");
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--path", u8"源码目录路径", true);
args_mode << std::make_shared<args_parse::FloatKeyValue>(u8"--dest", u8"生成目标目录");
entry_parser.loadMode(0x000bu, args_mode);
args_mode.clear();
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
args_mode << std::make_shared<args_parse::FloatOption>(u8"--make_anchor");
entry_parser.loadMode(0x000cu, args_mode);
args_mode.clear();
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
args_mode << std::make_shared<args_parse::FloatOption>(u8"--cmp");
entry_parser.loadMode(0x000du, args_mode);
args_mode.clear();
args_mode << std::make_shared<args_parse::IndexParam>(u8"程序名称");
args_mode << std::make_shared<args_parse::FloatOption>(u8"--graph");
entry_parser.loadMode(0x000eu, args_mode);
return a.exec();
}

View File

@ -0,0 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="17.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{DD802A96-BBB6-47CD-9B64-3582FD1805F3}</ProjectGuid>
<Keyword>QtVS_v304</Keyword>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">10.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">10.0</WindowsTargetPlatformVersion>
<QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')">$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v143</PlatformToolset>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
<Import Project="$(QtMsBuild)\qt_defaults.props" />
</ImportGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>debug</QtBuildConfig>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="QtSettings">
<QtInstall>5.12.11_msvc2017_64</QtInstall>
<QtModules>core</QtModules>
<QtBuildConfig>release</QtBuildConfig>
</PropertyGroup>
<Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" Condition="!Exists('$(QtMsBuild)\qt.targets') or !Exists('$(QtMsBuild)\qt.props')">
<Message Importance="High" Text="QtMsBuild: could not locate qt.targets, qt.props; project may not build correctly." />
</Target>
<ImportGroup Label="ExtensionSettings" />
<ImportGroup Label="Shared" />
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(QtMsBuild)\Qt.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<IncludePath>$(SolutionDir)ArgsParser;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
<TargetName>nsmt</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<TargetName>nsmt</TargetName>
<IncludePath>$(SolutionDir)ArgsParser;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)$(Platform)\$(Configuration);$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Link>
<AdditionalDependencies>ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Link>
<AdditionalDependencies>ArgsParser.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'" Label="Configuration">
<ClCompile>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'" Label="Configuration">
<ClCompile>
<MultiProcessorCompilation>true</MultiProcessorCompilation>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>false</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')">
<Import Project="$(QtMsBuild)\qt.targets" />
</ImportGroup>
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>qml;cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>qrc;rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Form Files">
<UniqueIdentifier>{99349809-55BA-4b9d-BF79-8FDBB0286EB3}</UniqueIdentifier>
<Extensions>ui</Extensions>
</Filter>
<Filter Include="Translation Files">
<UniqueIdentifier>{639EADAA-A684-42e4-A9AD-28FC9BCB8F7C}</UniqueIdentifier>
<Extensions>ts</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtTouchProperty>
</QtTouchProperty>
</PropertyGroup>
</Project>

51
WsNovelManager/main.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <QtCore/QCoreApplication>
#include <argsparser.h>
#include <iostream>
#include <QDebug>
using namespace args_parse;
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ArgsParser entry_parser;
auto help_mode = make_shared<MatchMode>(0x000au, u8"打印帮助信息!");
entry_parser << help_mode;
(*help_mode) << make_shared<IndexParam>(u8"nsmt", u8"程序名称")
<< make_shared<FloatOption>(u8"help", u8"帮助选项");
auto build_mode = make_shared<MatchMode>(0x000bu, u8"调用构建程序,编译故事线!");
entry_parser << build_mode;
(*build_mode) << make_shared<IndexParam>(u8"nsmt", u8"程序名称")
<< make_shared<FloatOption>(u8"nsc", u8"调用编译功能")
<< make_shared<FloatKeyValue>(u8"path", u8"源码目录路径", true)
<< make_shared<FloatKeyValue>(u8"dest", u8"生成目标目录");
auto anchor_mode = make_shared<MatchMode>(0x000cu, u8"设置里程碑");
entry_parser << anchor_mode;
(*anchor_mode) << make_shared<IndexParam>(u8"nsmt", u8"程序名称")
<< make_shared<FloatOption>(u8"mk_anchor", u8"设置里程碑");
auto cmp_mode = make_shared<MatchMode>(0x000du, u8"比较当前故事线和里程碑故事线");
entry_parser << cmp_mode;
(*cmp_mode) << make_shared<IndexParam>(u8"nsmt", u8"程序名称")
<< make_shared<FloatOption>(u8"cmp", u8"比较当前故事线内容");
auto graph_mode = make_shared<MatchMode>(0x000eu, u8"图形化显示当前内容");
entry_parser << graph_mode;
(*graph_mode) << make_shared<IndexParam>(u8"nsmt", u8"程序名称")
<< make_shared<FloatKeyValue>(u8"gmode", u8"设置图形化显示的模式");
auto rst = entry_parser.parse(argc, argv);
std::cout << rst << std::endl;
if (!rst) {
qDebug().noquote() << u8"命令行参数错误";
qDebug().noquote() << entry_parser.helpDoc();
return 0;
}
return 0;
}

View File

@ -33,6 +33,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ArgsParser", "ArgsParser\Ar
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StoryPresent", "StoryPresent\StoryPresent.vcxproj", "{48DA8516-26EA-4D59-8913-7EF28E3F87C3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WsNovelManager", "WsNovelManager\WsNovelManager.vcxproj", "{DD802A96-BBB6-47CD-9B64-3582FD1805F3}"
ProjectSection(ProjectDependencies) = postProject
{1FF80476-26C9-42FB-BFF6-D587C4941964} = {1FF80476-26C9-42FB-BFF6-D587C4941964}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
@ -63,6 +68,10 @@ Global
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Debug|x64.Build.0 = Debug|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.ActiveCfg = Release|x64
{48DA8516-26EA-4D59-8913-7EF28E3F87C3}.Release|x64.Build.0 = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.ActiveCfg = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Debug|x64.Build.0 = Debug|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.ActiveCfg = Release|x64
{DD802A96-BBB6-47CD-9B64-3582FD1805F3}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -40,15 +40,11 @@ int main(int argc, char* argv[]) {
auto p_result = args_parser.parse(argc, argv);
if (!p_result) {
qDebug().noquote() << u8"命令行参数错误!";
qDebug().noquote() << args_parser.helpDoc();
}
else {
switch (p_result->modeCode()) {
case 0xAu:
default:
qDebug().noquote() << u8"命令行参数错误!";
qDebug().noquote() << args_parser.helpDoc();
break;
case 0xBu:
{
auto src_dir = dynamic_pointer_cast<FloatKeyValue>(p_result->getUnitViaKey(u8"path"));
@ -119,6 +115,10 @@ int main(int argc, char* argv[]) {
qDebug().noquote() << QString(u8"%编译成功:%1。").arg(QFileInfo(file).absoluteFilePath());
}
}break;
case 0xAu:
default:
qDebug().noquote() << args_parser.helpDoc();
break;
}
}
//return a.exec();