Add skeleton for ArgumentParser in Utils component

This commit is contained in:
Jan 2019-09-24 23:33:08 +02:00
parent 9f198ce7a2
commit 8991b6ab15
5 changed files with 118 additions and 0 deletions

View File

@ -19,11 +19,15 @@
</ProjectConfiguration> </ProjectConfiguration>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Utils\Arguments\ArgumentParser.h" />
<ClInclude Include="Utils\Arguments\CommandLineOption.h" />
<ClInclude Include="Utils\ClassUtils.h" /> <ClInclude Include="Utils\ClassUtils.h" />
<ClInclude Include="Utils\FileAPI.h" /> <ClInclude Include="Utils\FileAPI.h" />
<ClInclude Include="Utils\PathUtils.h" /> <ClInclude Include="Utils\PathUtils.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="Utils\Arguments\ArgumentParser.cpp" />
<ClCompile Include="Utils\Arguments\CommandLineOption.cpp" />
<ClCompile Include="Utils\FileAPI.cpp" /> <ClCompile Include="Utils\FileAPI.cpp" />
<ClCompile Include="Utils\PathUtils.cpp" /> <ClCompile Include="Utils\PathUtils.cpp" />
</ItemGroup> </ItemGroup>

View File

@ -0,0 +1,19 @@
#pragma once
#include "CommandLineOption.h"
#include <string>
#include <vector>
class ArgumentParser
{
public:
ArgumentParser(const CommandLineOption** options, size_t optionCount);
bool ParseArguments(std::vector<std::string>& args);
bool ParseArguments(int argc, const char** argv);
std::vector<std::string> GetArguments();
bool IsOptionSpecified(const CommandLineOption* option);
std::string GetValueForOption(const CommandLineOption* option);
std::vector<std::string> GetParametersForOption(const CommandLineOption* option);
};

View File

@ -0,0 +1,60 @@
#include "CommandLineOption.h"
#include <Windows.h>
CommandLineOption::CommandLineOption()
{
m_short_name = "";
m_long_name = "";
m_description = "";
m_category = "";
m_multi_use = false;
}
CommandLineOption::Builder& CommandLineOption::Builder::Create()
{
return *new Builder();
}
CommandLineOption::Builder& CommandLineOption::Builder::WithShortName(std::string shortName)
{
m_option.m_short_name = std::move(shortName);
return *this;
}
CommandLineOption::Builder& CommandLineOption::Builder::WithLongName(std::string longName)
{
m_option.m_long_name = std::move(longName);
return *this;
}
CommandLineOption::Builder& CommandLineOption::Builder::WithDescription(std::string description)
{
m_option.m_description = std::move(description);
return *this;
}
CommandLineOption::Builder& CommandLineOption::Builder::WithCategory(std::string category)
{
m_option.m_category = std::move(category);
return *this;
}
CommandLineOption::Builder& CommandLineOption::Builder::WithParameter(std::string parameterName)
{
m_option.m_parameters.push_back(std::move(parameterName));
return *this;
}
CommandLineOption::Builder& CommandLineOption::Builder::Reusable()
{
m_option.m_multi_use = true;
return *this;
}
CommandLineOption* CommandLineOption::Builder::Build() const
{
auto* result = new CommandLineOption(m_option);
delete this;
return result;
}

View File

@ -0,0 +1,35 @@
#pragma once
#include <string>
#include <vector>
class CommandLineOption
{
protected:
CommandLineOption();
public:
std::string m_short_name;
std::string m_long_name;
std::string m_description;
std::string m_category;
bool m_multi_use;
std::vector<std::string> m_parameters;
class Builder;
};
class CommandLineOption::Builder
{
CommandLineOption m_option;
public:
static Builder& Create();
Builder& WithShortName(std::string shortName);
Builder& WithLongName(std::string longName);
Builder& WithDescription(std::string description);
Builder& WithCategory(std::string category);
Builder& WithParameter(std::string parameterName);
Builder& Reusable();
CommandLineOption* Build() const;
};