| 9525 | } |
| 9526 | |
| 9527 | void writeToStream( std::ostream &os ) const { |
| 9528 | if (!m_exeName.name().empty()) { |
| 9529 | os << "usage:\n" << " " << m_exeName.name() << " "; |
| 9530 | bool required = true, first = true; |
| 9531 | for( auto const &arg : m_args ) { |
| 9532 | if (first) |
| 9533 | first = false; |
| 9534 | else |
| 9535 | os << " "; |
| 9536 | if( arg.isOptional() && required ) { |
| 9537 | os << "["; |
| 9538 | required = false; |
| 9539 | } |
| 9540 | os << "<" << arg.hint() << ">"; |
| 9541 | if( arg.cardinality() == 0 ) |
| 9542 | os << " ... "; |
| 9543 | } |
| 9544 | if( !required ) |
| 9545 | os << "]"; |
| 9546 | if( !m_options.empty() ) |
| 9547 | os << " options"; |
| 9548 | os << "\n\nwhere options are:" << std::endl; |
| 9549 | } |
| 9550 | |
| 9551 | auto rows = getHelpColumns(); |
| 9552 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 9553 | size_t optWidth = 0; |
| 9554 | for( auto const &cols : rows ) |
| 9555 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 9556 | |
| 9557 | optWidth = (std::min)(optWidth, consoleWidth/2); |
| 9558 | |
| 9559 | for( auto const &cols : rows ) { |
| 9560 | auto row = |
| 9561 | TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + |
| 9562 | TextFlow::Spacer(4) + |
| 9563 | TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); |
| 9564 | os << row << std::endl; |
| 9565 | } |
| 9566 | } |
| 9567 | |
| 9568 | friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { |
| 9569 | parser.writeToStream( os ); |
no test coverage detected