| 9468 | } |
| 9469 | |
| 9470 | void writeToStream( std::ostream &os ) const { |
| 9471 | if (!m_exeName.name().empty()) { |
| 9472 | os << "usage:\n" << " " << m_exeName.name() << " "; |
| 9473 | bool required = true, first = true; |
| 9474 | for( auto const &arg : m_args ) { |
| 9475 | if (first) |
| 9476 | first = false; |
| 9477 | else |
| 9478 | os << " "; |
| 9479 | if( arg.isOptional() && required ) { |
| 9480 | os << "["; |
| 9481 | required = false; |
| 9482 | } |
| 9483 | os << "<" << arg.hint() << ">"; |
| 9484 | if( arg.cardinality() == 0 ) |
| 9485 | os << " ... "; |
| 9486 | } |
| 9487 | if( !required ) |
| 9488 | os << "]"; |
| 9489 | if( !m_options.empty() ) |
| 9490 | os << " options"; |
| 9491 | os << "\n\nwhere options are:" << std::endl; |
| 9492 | } |
| 9493 | |
| 9494 | auto rows = getHelpColumns(); |
| 9495 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 9496 | size_t optWidth = 0; |
| 9497 | for( auto const &cols : rows ) |
| 9498 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 9499 | |
| 9500 | optWidth = (std::min)(optWidth, consoleWidth/2); |
| 9501 | |
| 9502 | for( auto const &cols : rows ) { |
| 9503 | auto row = |
| 9504 | TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + |
| 9505 | TextFlow::Spacer(4) + |
| 9506 | TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); |
| 9507 | os << row << std::endl; |
| 9508 | } |
| 9509 | } |
| 9510 | |
| 9511 | friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { |
| 9512 | parser.writeToStream( os ); |
no test coverage detected