Commit 37122edba1ee18cdab879681d14126e0497608d6

Authored by Jarryd Beck
1 parent 8a86fbc3

writing parser

src/cxxopts.cpp
... ... @@ -91,6 +91,7 @@ Options::parse(int& argc, char**& argv)
91 91  
92 92 if (iter == m_short.end())
93 93 {
  94 + throw option_not_exists_exception(name);
94 95 //argument not found
95 96 }
96 97  
... ... @@ -111,6 +112,7 @@ Options::parse(int& argc, char**& argv)
111 112 else
112 113 {
113 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 125  
124 126 if (iter == m_long.end())
125 127 {
  128 + throw option_not_exists_exception(name);
126 129 }
127 130  
128 131 auto opt = iter->second;
... ...
src/cxxopts.hpp
... ... @@ -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 119 class OptionAdder;
102 120  
103 121 class OptionDetails
... ...