|
- #pragma once
-
- #include <cpputils/misc/indent.h>
- #include <cppargs/misc/printing.h>
-
- namespace cppargs
- {
-
- void printing::operator()(std::ostream& os, const group& g) const
- { print_group(os, g); }
-
- void printing::print_group(std::ostream& os, const group& g) const
- {
- using namespace ::utl;
-
- /* meta */
- if (!g.meta.name.empty())
- {
- os << indent << "-= " << g.meta.name << " =-"
- << std::endl;
- }
- if (!g.meta.description.empty())
- {
- os << indent << g.meta.description
- << std::endl;
- }
-
- os << incindent;
-
- /* options */
- bool has_option = false;
- for (auto& o : g.options())
- {
- if (!has_option)
- has_option = true;
- else
- os << std::endl;
- print_option(os, *o);
- }
- if (has_option)
- os << std::endl;
-
- os << decindent;
-
- /* groups */
- for (auto& i : g.groups())
- {
- print_group(os, *i);
- }
- }
-
- void printing::print_option(std::ostream& os, const option& o) const
- {
- using namespace ::utl;
- auto& m = o.meta;
- os << indent;
- if (m.short_name != '\0')
- os << '-' << m.short_name;
- if (m.short_name != '\0' && !m.long_name.empty())
- os << '|';
- if (!m.long_name.empty())
- os << "--" << m.long_name;
- if (!m.arguments.empty())
- os << " " << m.arguments;
- os << incindent;
- if (!m.description.empty())
- os << indent << m.description;
- if (!m.default_value.empty())
- os << indent << "Default value: " << m.default_value;
- if (m.mandatory)
- os << indent << "This option is mandatory.";
- os << decindent;
- }
-
- }
|