| 6113 | } |
| 6114 | |
| 6115 | void writeToStream(std::ostream &os) const { |
| 6116 | if (!m_exeName.name().empty()) { |
| 6117 | os << "usage:\n" |
| 6118 | << " " << m_exeName.name() << " "; |
| 6119 | bool required = true, first = true; |
| 6120 | for (auto const &arg : m_args) { |
| 6121 | if (first) |
| 6122 | first = false; |
| 6123 | else |
| 6124 | os << " "; |
| 6125 | if (arg.isOptional() && required) { |
| 6126 | os << "["; |
| 6127 | required = false; |
| 6128 | } |
| 6129 | os << "<" << arg.hint() << ">"; |
| 6130 | if (arg.cardinality() == 0) |
| 6131 | os << " ... "; |
| 6132 | } |
| 6133 | if (!required) |
| 6134 | os << "]"; |
| 6135 | if (!m_options.empty()) |
| 6136 | os << " options"; |
| 6137 | os << "\n\nwhere options are:" << std::endl; |
| 6138 | } |
| 6139 | |
| 6140 | auto rows = getHelpColumns(); |
| 6141 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 6142 | size_t optWidth = 0; |
| 6143 | for (auto const &cols : rows) |
| 6144 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 6145 | |
| 6146 | optWidth = (std::min)(optWidth, consoleWidth / 2); |
| 6147 | |
| 6148 | for (auto const &cols : rows) { |
| 6149 | auto row = TextFlow::Column(cols.left).width(optWidth).indent(2) + TextFlow::Spacer(4) + |
| 6150 | TextFlow::Column(cols.right).width(consoleWidth - 7 - optWidth); |
| 6151 | os << row << std::endl; |
| 6152 | } |
| 6153 | } |
| 6154 | |
| 6155 | friend auto operator<<(std::ostream &os, Parser const &parser) -> std::ostream & { |
| 6156 | parser.writeToStream(os); |
no test coverage detected