Commit 37122edba1ee18cdab879681d14126e0497608d6
1 parent
8a86fbc3
writing parser
Showing
2 changed files
with
21 additions
and
0 deletions
src/cxxopts.cpp
| @@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv) | @@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv) | ||
| 91 | 91 | ||
| 92 | if (iter == m_short.end()) | 92 | if (iter == m_short.end()) |
| 93 | { | 93 | { |
| 94 | + throw option_not_exists_exception(name); | ||
| 94 | //argument not found | 95 | //argument not found |
| 95 | } | 96 | } |
| 96 | 97 | ||
| @@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv) | @@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv) | ||
| 111 | else | 112 | else |
| 112 | { | 113 | { |
| 113 | //error | 114 | //error |
| 115 | + throw option_requires_argument_exception(name); | ||
| 114 | } | 116 | } |
| 115 | } | 117 | } |
| 116 | } | 118 | } |
| @@ -123,6 +125,7 @@ Options::parse(int& argc, char**& argv) | @@ -123,6 +125,7 @@ Options::parse(int& argc, char**& argv) | ||
| 123 | 125 | ||
| 124 | if (iter == m_long.end()) | 126 | if (iter == m_long.end()) |
| 125 | { | 127 | { |
| 128 | + throw option_not_exists_exception(name); | ||
| 126 | } | 129 | } |
| 127 | 130 | ||
| 128 | auto opt = iter->second; | 131 | auto opt = iter->second; |
src/cxxopts.hpp
| @@ -98,6 +98,24 @@ namespace cxxopts | @@ -98,6 +98,24 @@ namespace cxxopts | ||
| 98 | } | 98 | } |
| 99 | }; | 99 | }; |
| 100 | 100 | ||
| 101 | + class option_not_exists_exception : public OptionParseException | ||
| 102 | + { | ||
| 103 | + public: | ||
| 104 | + option_not_exists_exception(const std::string& option) | ||
| 105 | + : OptionParseException(u8"Option ‘" + option + u8"’ does not exist") | ||
| 106 | + { | ||
| 107 | + } | ||
| 108 | + }; | ||
| 109 | + | ||
| 110 | + class option_requires_argument_exception : public OptionParseException | ||
| 111 | + { | ||
| 112 | + public: | ||
| 113 | + option_requires_argument_exception(const std::string& option) | ||
| 114 | + : OptionParseException(u8"Option ‘" + option + u8"’ requires an argument") | ||
| 115 | + { | ||
| 116 | + } | ||
| 117 | + }; | ||
| 118 | + | ||
| 101 | class OptionAdder; | 119 | class OptionAdder; |
| 102 | 120 | ||
| 103 | class OptionDetails | 121 | class OptionDetails |