writing parser

This commit is contained in:
Jarryd Beck 2014-09-28 21:41:19 +10:00
parent 8a86fbc32f
commit 37122edba1
2 changed files with 21 additions and 0 deletions

View File

@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv)
if (iter == m_short.end()) if (iter == m_short.end())
{ {
throw option_not_exists_exception(name);
//argument not found //argument not found
} }
@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv)
else else
{ {
//error //error
throw option_requires_argument_exception(name);
} }
} }
} }
@ -123,6 +125,7 @@ Options::parse(int& argc, char**& argv)
if (iter == m_long.end()) if (iter == m_long.end())
{ {
throw option_not_exists_exception(name);
} }
auto opt = iter->second; auto opt = iter->second;

View File

@ -98,6 +98,24 @@ namespace cxxopts
} }
}; };
class option_not_exists_exception : public OptionParseException
{
public:
option_not_exists_exception(const std::string& option)
: OptionParseException(u8"Option " + option + u8" does not exist")
{
}
};
class option_requires_argument_exception : public OptionParseException
{
public:
option_requires_argument_exception(const std::string& option)
: OptionParseException(u8"Option " + option + u8" requires an argument")
{
}
};
class OptionAdder; class OptionAdder;
class OptionDetails class OptionDetails