| 7423 | } |
| 7424 | |
| 7425 | void writeToStream( std::ostream &os ) const { |
| 7426 | if (!m_exeName.name().empty()) { |
| 7427 | os << "usage:\n" << " " << m_exeName.name() << " "; |
| 7428 | bool required = true, first = true; |
| 7429 | for( auto const &arg : m_args ) { |
| 7430 | if (first) |
| 7431 | first = false; |
| 7432 | else |
| 7433 | os << " "; |
| 7434 | if( arg.isOptional() && required ) { |
| 7435 | os << "["; |
| 7436 | required = false; |
| 7437 | } |
| 7438 | os << "<" << arg.hint() << ">"; |
| 7439 | if( arg.cardinality() == 0 ) |
| 7440 | os << " ... "; |
| 7441 | } |
| 7442 | if( !required ) |
| 7443 | os << "]"; |
| 7444 | if( !m_options.empty() ) |
| 7445 | os << " options"; |
| 7446 | os << "\n\nwhere options are:" << std::endl; |
| 7447 | } |
| 7448 | |
| 7449 | auto rows = getHelpColumns(); |
| 7450 | size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; |
| 7451 | size_t optWidth = 0; |
| 7452 | for( auto const &cols : rows ) |
| 7453 | optWidth = (std::max)(optWidth, cols.left.size() + 2); |
| 7454 | |
| 7455 | optWidth = (std::min)(optWidth, consoleWidth/2); |
| 7456 | |
| 7457 | for( auto const &cols : rows ) { |
| 7458 | auto row = |
| 7459 | TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + |
| 7460 | TextFlow::Spacer(4) + |
| 7461 | TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); |
| 7462 | os << row << std::endl; |
| 7463 | } |
| 7464 | } |
| 7465 | |
| 7466 | friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { |
| 7467 | parser.writeToStream( os ); |
no test coverage detected