| 9552 | } |
| 9553 | |
| 9554 | void writeToStream( std::ostream &os ) const { |
| 9555 | if (!m_exeName.name().empty()) { |
| 9556 | os << "usage:\n" << " " << m_exeName.name() << " "; |
| 9557 | bool required = true, first = true; |
| 9558 | for( auto const &arg : m_args ) { |
| 9559 | if (first) |
| 9560 | first = false; |
| 9561 | else |
| 9562 | os << " "; |
| 9563 | if( arg.isOptional() && required ) { |
| 9564 | os << "["; |
| 9565 | required = false; |
| 9566 | } |
| 9567 | os << "<" << arg.hint() << ">"; |
| 9568 | if( arg.cardinality() == 0 ) |
| 9569 | os << " ... "; |
| 9570 | } |
| 9571 | if( !required ) |
| 9572 | os << "]"; |
| 9573 | if( !m_options.empty() ) |
| 9574 | os << " options"; |
| 9575 | os << "\n\nwhere options are:" << std::endl; |
| 9576 | } |
| 9577 | |
| 9578 | auto rows = getHelpColumns(); |
| 9579 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 9580 | size_t optWidth = 0; |
| 9581 | for( auto const &cols : rows ) |
| 9582 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 9583 | |
| 9584 | optWidth = (std::min)(optWidth, consoleWidth/2); |
| 9585 | |
| 9586 | for( auto const &cols : rows ) { |
| 9587 | auto row = |
| 9588 | TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + |
| 9589 | TextFlow::Spacer(4) + |
| 9590 | TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); |
| 9591 | os << row << std::endl; |
| 9592 | } |
| 9593 | } |
| 9594 | |
| 9595 | friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { |
| 9596 | parser.writeToStream( os ); |
no test coverage detected