| 181 | } |
| 182 | |
| 183 | inline bool CommandLineParser::validate() const |
| 184 | { |
| 185 | bool is_valid = true; |
| 186 | |
| 187 | for (const auto &option : _options) |
| 188 | { |
| 189 | if (option.second->is_required() && !option.second->is_set()) |
| 190 | { |
| 191 | is_valid = false; |
| 192 | std::cerr << "ERROR: Option '" << option.second->name() << "' is required but not given!\n"; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | for (const auto &option : _positional_options) |
| 197 | { |
| 198 | if (option->is_required() && !option->is_set()) |
| 199 | { |
| 200 | is_valid = false; |
| 201 | std::cerr << "ERROR: Option '" << option->name() << "' is required but not given!\n"; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | for (const auto &option : _unknown_options) |
| 206 | { |
| 207 | std::cerr << "WARNING: Skipping unknown option '" << option << "'!\n"; |
| 208 | } |
| 209 | |
| 210 | for (const auto &option : _invalid_options) |
| 211 | { |
| 212 | std::cerr << "WARNING: Skipping invalid option '" << option << "'!\n"; |
| 213 | } |
| 214 | |
| 215 | return is_valid; |
| 216 | } |
| 217 | |
| 218 | inline void CommandLineParser::print_help(const std::string &program_name) const |
| 219 | { |
nothing calls this directly
no test coverage detected