check if this is a valid option before adding
| 232 | |
| 233 | // check if this is a valid option before adding |
| 234 | void |
| 235 | ArgParser::Command::check_option(std::string const &long_option, std::string const &short_option, |
| 236 | std::string const & /* key ATS_UNUSED */) const |
| 237 | { |
| 238 | if (long_option.size() < 3 || long_option[0] != '-' || long_option[1] != '-') { |
| 239 | // invalid name |
| 240 | std::cerr << "Error: invalid long option added: '" + long_option + "'" << std::endl; |
| 241 | exit(1); |
| 242 | } |
| 243 | if (short_option.size() > 2 || (short_option.size() > 0 && short_option[0] != '-')) { |
| 244 | // invalid short option |
| 245 | std::cerr << "Error: invalid short option added: '" + short_option + "'" << std::endl; |
| 246 | exit(1); |
| 247 | } |
| 248 | // find if existing in option list |
| 249 | if (_option_list.find(long_option) != _option_list.end()) { |
| 250 | std::cerr << "Error: long option '" + long_option + "' already existed" << std::endl; |
| 251 | exit(1); |
| 252 | } else if (_option_map.find(short_option) != _option_map.end()) { |
| 253 | std::cerr << "Error: short option '" + short_option + "' already existed" << std::endl; |
| 254 | exit(1); |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // check if this is a valid command before adding |
| 259 | void |