You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.1 KiB

2 months ago
  1. #include <iostream>
  2. #include "popl.hpp"
  3. #include "OptionParser.h"
  4. namespace io {
  5. int printPoplException(const popl::invalid_option &e) {
  6. std::cerr << "Invalid Option Exception: " << e.what() << "\n";
  7. std::cerr << "error: ";
  8. if (e.error() == popl::invalid_option::Error::missing_argument) {
  9. std::cerr << "missing_argument\n";
  10. } else if (e.error() == popl::invalid_option::Error::invalid_argument) {
  11. std::cerr << "invalid_argument\n";
  12. } else if (e.error() == popl::invalid_option::Error::too_many_arguments) {
  13. std::cerr << "too_many_arguments\n";
  14. } else if (e.error() == popl::invalid_option::Error::missing_option) {
  15. std::cerr << "missing_option\n";
  16. }
  17. if (e.error() == popl::invalid_option::Error::missing_option) {
  18. std::string option_name(e.option()->name(popl::OptionName::short_name, true));
  19. if (option_name.empty())
  20. option_name = e.option()->name(popl::OptionName::long_name, true);
  21. std::cerr << "option: " << option_name << "\n";
  22. }
  23. else {
  24. std::cerr << "option: " << e.option()->name(e.what_name()) << "\n";
  25. std::cerr << "value: " << e.value() << "\n";
  26. }
  27. return EXIT_FAILURE;
  28. }
  29. }