From 37122edba1ee18cdab879681d14126e0497608d6 Mon Sep 17 00:00:00 2001 From: Jarryd Beck Date: Sun, 28 Sep 2014 21:41:19 +1000 Subject: [PATCH] writing parser --- src/cxxopts.cpp | 3 +++ src/cxxopts.hpp | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/src/cxxopts.cpp b/src/cxxopts.cpp index fb43c25..fa6146c 100644 --- a/src/cxxopts.cpp +++ b/src/cxxopts.cpp @@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv) if (iter == m_short.end()) { + throw option_not_exists_exception(name); //argument not found } @@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv) else { //error + throw option_requires_argument_exception(name); } } } @@ -123,6 +125,7 @@ Options::parse(int& argc, char**& argv) if (iter == m_long.end()) { + throw option_not_exists_exception(name); } auto opt = iter->second; diff --git a/src/cxxopts.hpp b/src/cxxopts.hpp index f45cf0b..90b4148 100644 --- a/src/cxxopts.hpp +++ b/src/cxxopts.hpp @@ -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 OptionDetails -- libgit2 0.21.4