25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

76 satır
1.8 KiB

  1. #pragma once
  2. #include <cpputils/misc/indent.h>
  3. #include <cppargs/misc/printing.h>
  4. namespace cppargs
  5. {
  6. void printing::operator()(std::ostream& os, const group& g) const
  7. { print_group(os, g); }
  8. void printing::print_group(std::ostream& os, const group& g) const
  9. {
  10. using namespace ::utl;
  11. /* meta */
  12. if (!g.meta.name.empty())
  13. {
  14. os << indent << "-= " << g.meta.name << " =-"
  15. << std::endl;
  16. }
  17. if (!g.meta.description.empty())
  18. {
  19. os << indent << g.meta.description
  20. << std::endl;
  21. }
  22. os << incindent;
  23. /* options */
  24. bool has_option = false;
  25. for (auto& o : g.options())
  26. {
  27. if (!has_option)
  28. has_option = true;
  29. else
  30. os << std::endl;
  31. print_option(os, *o);
  32. }
  33. if (has_option)
  34. os << std::endl;
  35. os << decindent;
  36. /* groups */
  37. for (auto& i : g.groups())
  38. {
  39. print_group(os, *i);
  40. }
  41. }
  42. void printing::print_option(std::ostream& os, const option& o) const
  43. {
  44. using namespace ::utl;
  45. auto& m = o.meta;
  46. os << indent;
  47. if (m.short_name != '\0')
  48. os << '-' << m.short_name;
  49. if (m.short_name != '\0' && !m.long_name.empty())
  50. os << '|';
  51. if (!m.long_name.empty())
  52. os << "--" << m.long_name;
  53. if (!m.arguments.empty())
  54. os << " " << m.arguments;
  55. os << incindent;
  56. if (!m.description.empty())
  57. os << indent << m.description;
  58. if (!m.default_value.empty())
  59. os << indent << "Default value: " << m.default_value;
  60. if (m.mandatory)
  61. os << indent << "This option is mandatory.";
  62. os << decindent;
  63. }
  64. }